views:

101

answers:

4

SELECT item_name from items WHERE item_id = $var;

I tried:

$var = 001 || 002 || 003 || 004;

$var = 001 OR 002 OR 003 OR 004;

$var = 001 or 002 or 003 or 004;

But all do not work.

Thanks, i try that, but the output only 1 result => 1.

What I want is to output all, i.e. 1, 2 , 3 and 4.. Means, I want to select multiple records(rows) from 1 column

How to do that?

+7  A: 
SELECT item_name from items WHERE item_id IN (1, 2, 3, 4)

And if item_id is a VARCHAR for some reason:

SELECT item_name from items WHERE item_id IN ('001', '002', '003', '004')
Sean Bright
+2  A: 

Or you could use:

SELECT item_name from items WHERE item_id = 001 OR item_id = 002 etc.

+1  A: 

the correct SQL sintax would be:

SELECT item_name from items WHERE item_id = 001 or item_id = 002 or item_id=003;
Luis Melgratti
+1  A: 

You've got bigger problems than the question you've posed. The query you are trying to write is trivial and the fact that you are a little lost with it is not good.

If I were you, I'd take a step back and review a couple tutorials on sql. Spend a few hours (or a few days) learning the topic before proceeding.

Of course, you could just try to 'get the task done', but you will likely have significant security and/or performance issues with the queries you write.

There are a lot of good tutorials out there. Go read them.

Good luck!

mson