-1

How would I use multiple values in the WHERE of a mysqli_query??

ex.

mysqli_query ($con, "SELECT post_title, post_content, post_date FROM posts WHERE post_id = 3013, 4140, 6850")

Is that the correct way to use multiple WHERE values? or...?

kmkmkm
  • 79
  • 2
  • 12
  • Please use the search. This is first of all a SQL question independent to the database client library used. – hakre Jul 10 '13 at 14:51

4 Answers4

4

use IN

WHERE post_id IN (3013, 4140, 6850)

which is the same with

WHERE post_id = 3013 OR
      post_id = 4140 OR
      post_id = 6850
John Woo
  • 258,903
  • 69
  • 498
  • 492
0

You need to use IN clause.

mysqli_query ($con, "SELECT post_title, post_content, post_date FROM posts WHERE post_id IN (3013, 4140, 6850)")
Nasir
  • 10,935
  • 8
  • 31
  • 39
0

Use IN:

mysqli_query ($con, "SELECT post_title, post_content, post_date FROM posts WHERE post_id IN (3013, 4140, 6850)")
0

First you should check the documentation:

select syntax

And you seperate your where clauses with AND or OR

Tobias Golbs
  • 4,586
  • 3
  • 28
  • 49