Register a domain and help support LQ
Go Back > Forums > Non-*NIX Forums > Programming
User Name
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.


  Search this Thread
Old 07-02-2007, 10:07 AM   #1
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, 10:09 AM   #2
Senior Member
Registered: Dec 2003
Location: Trondheim, Norway
Distribution: Debian and Ubuntu
Posts: 1,203

Rep: Reputation: 265Reputation: 265Reputation: 265

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

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


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

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

All times are GMT -5. The time now is 11:20 AM.

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