Alfred
Alfred

Reputation: 21396

find row from mysql table with multiple parameters (from different columns) using php

I have a mysql table as below:

--------------------
| Sl | col1 | col2 |   
--------------------
| 1  | data1| msg1 | 
--------------------
| 2  | data2| msg2 | 
--------------------
| 3  | data1| msg3 | 
--------------------
| 4  | data2| msg4 | 
--------------------
| 5  | data1| msg5 | 
--------------------

I have a php string $query = "select * from table WHERE col1='data1'"; , which fetch array 3 results (row number 1, 3, and 5). But i want to get a specific row containing "data1" in "col1" and "msg3" in "col2" (which is row number 3) in a single query. How can I make this possible?

Upvotes: 1

Views: 3226

Answers (1)

moinudin
moinudin

Reputation: 138347

Use AND in the WHERE clause to match multiple conditions:

SELECT * FROM table WHERE col1='data1' AND col2='msg3'

Upvotes: 6

Related Questions