roa3
roa3

Reputation: 901

How to do this query in mysql?

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?

Upvotes: 1

Views: 490

Answers (4)

mson
mson

Reputation: 7824

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!

Upvotes: 1

Luis Melgratti
Luis Melgratti

Reputation: 12050

the correct SQL sintax would be:

SELECT item_name from items WHERE item_id = 001 or item_id = 002 or item_id=003;

Upvotes: 1

Me_here
Me_here

Reputation:

Or you could use:

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

Upvotes: 2

Sean Bright
Sean Bright

Reputation: 120644

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')

Upvotes: 7

Related Questions