
Originally Posted by
Mikl
// Match all manufacturers
SELECT * from DB WHERE Manufacturer LIKE '%'
this will work efficiently provided that mysql is smart enough to optimize away the WHERE condition
in my opinion, it's better not to generate the WHERE condition in the first place, if you want all manufacturers
but it can get tricky if there is more than one condition, because then there's the question of which one comes right after the WHERE keyword, and which one comes after the AND keyword
the neat workaround for this is to begin each WHERE clause with which i know does get optimized away
then in deciding whether other conditions are to be generated, all you have to do is preface each of them with AND
Code:
WHERE 1=1 -- all manufacturers, all prices
Code:
WHERE 1=1 AND manufacturer="samsung" -- all prices
Code:
WHERE 1=1 AND price = 9.37 -- all manufacturers
Code:
WHERE 1=1 AND manufacturer="samsung" AND price = 9.37
Bookmarks