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!

admin

Recent Posts

The Ultimate Guide to Effective Meetings

In today’s fast-paced work environment, meetings are essential but can often feel unproductive. However, by…

2 months ago

From Mine to Market: How Gold Is Mined, Refined, and Sold in Shops

Gold is one of the most coveted precious metals in the world, adored for its…

3 months ago

The Historical Journey of Gold: From Ancient Civilizations to Modern Times

Gold, the shimmering metal synonymous with wealth, power, and beauty, has been deeply intertwined with…

3 months ago

How to Onboard an Intern in Small, Individual-Based Company

How to Onboard an Intern in a Small, Individual-Based Company Hiring an intern can be…

4 months ago