Alex Manzano Alex Manzano - 3 months ago 10
MySQL Question

How to debug a failing SELECT statement?

Is there a simple explanation why this query doesn't work, and what is its alternative?

SELECT * FROM items WHERE item_category = 'shirts'
AND WHERE item_category = 'pants'


I have to keep the clause:

SELECT * FROM items


because I need all the data that is selected for later use.

Answer

Don't include WHERE twice:

SELECT * FROM items WHERE item_category = 'shirts' OR item_category = 'pants'

You also don't want to specify "AND", because there won't be a point where both item_category will be shirts and pants at the same time.

Comments