How to make this query in mysql?

SELECT item_name from elements 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 everything does not work.

Thanks, I try this, but the output is only 1 result => 1.

I want to output everything, i.e. 1, 2, 3 and 4 .. So, I want to select several records (rows) from 1 column

How to do it?

0
source share
4 answers
 SELECT item_name from items WHERE item_id IN (1, 2, 3, 4) 

And if item_id is VARCHAR for any reason:

 SELECT item_name from items WHERE item_id IN ('001', '002', '003', '004') 
+7
source

Or you could use:

SELECT item_name from WHERE elements item_id = 001 OR item_id = 002, etc.

+2
source

correct SQL syntax:

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

You have bigger problems than the question you asked. The query you are trying to write is trivial, and the fact that you lost it a little is not very good.

If I were you, I would take a step back and review a couple of sql tutorials. Spend several hours (or several days) studying the topic before continuing.

Of course, you can just try to β€œcomplete the task”, but you are likely to have serious security and / or performance issues with the queries you write.

There are many good tutorials. Go read them.

Good luck

+1
source

All Articles