Categories
Learning

What is the syntax or how to add AND with where clause in PHP MYSQL?

Hello, welcome to this short post or an answer for this question.

Here is example do use AND with WHERE clause in MYSQL statement in PHP or general writing of SQL Statement.

SELECT *
FROM orders
WHERE (userId = 111 AND orderId = 185)

This how we can use AND in where clause., similarly if we need OR in WHERE clause, we can use as below:

SELECT *
FROM orders
WHERE (userId = 111 AND orderId = 185)
OR (userId > 100);

Just if we are looking for complex query with multiple OR and AND in OR

SELECT orderId, orderNumber, orderStatus
FROM orders
WHERE (orderId = 185)
OR (orderNumber = 101 AND orderStatus = 'Cancelled')
OR (orderNumber = 102 AND orderStatus = 'InProgress' AND total >=500);

Purpose of this post to give you just syntax you might be looking for, but you know the logic how to implement it and use it!

Thanks for visiting and happy learning!