LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
LinkBack Search this Thread
Old 07-02-2007, 09:07 AM   #1
elvijs
LQ Newbie
 
Registered: Nov 2006
Location: Latvia
Distribution: Slackware
Posts: 15

Rep: Reputation: 0
SQL: multiple WHERE statements


Is something like this possible in a "clean" way?

SELECT * FROM table WHERE id = '1' OR id = '11' OR id = '9' OR id = '4' OR id = '6'
and so on...

For example I want to select information only about particular records (using PHP). I have an array with the records' ids (the size of array is unknown). Can I do something like this or is it impossible?

SELECT * FROM table WHERE id = '$array';
 
Old 07-02-2007, 09:09 AM   #2
Guttorm
Senior Member
 
Registered: Dec 2003
Location: Trondheim, Norway
Distribution: Debian and Ubuntu
Posts: 1,089

Rep: Reputation: 207Reputation: 207Reputation: 207
Hi

Try this:
PHP Code:
$ids join(",",$array);
$sql "SELECT * FROM table WHERE id IN ($ids)"
 
Old 07-02-2007, 09:17 AM   #3
elvijs
LQ Newbie
 
Registered: Nov 2006
Location: Latvia
Distribution: Slackware
Posts: 15

Original Poster
Rep: Reputation: 0
Really thanks, it works.
 
  


Reply

Tags
multiple, sql


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Multiple My Sql processes veenaonnet Linux - Newbie 1 05-03-2007 08:58 AM
java code executing SQL statements problem randomx Programming 1 11-09-2004 10:59 AM
if statements and case statements not working in bourne shell script mparkhurs Programming 3 06-12-2004 02:41 AM
SQL: making queries from multiple tables ganninu Programming 1 01-08-2004 11:17 AM
Multiple values with SQL (Noob stuff) Travis86 Programming 6 09-03-2003 08:38 PM


All times are GMT -5. The time now is 03:04 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration