I have a query that uses a where clause. At times, this may be used and at others, I may want to omit it completely to get back all results. I can certainly write two different queries but I would like to cut down on any code that I can for simplistic reasons. Is there a way to do this in mysql?
Take a query like:
SELECT * FROM my_table WHERE id = '3'
and:
SELECT * FROM my_table
Is there a way to use the top query and still get back all records?
More food for thought…
I notice you quoted the ‘3’. If your ids are char data you could use the LIKE string comparison operator.
For a single value
For all values
Won’t give you any values with NULL id though.