I use some sql like this:
SELECT COALESCE(group.display,item.display) as display....
I would like to add in the WHERE clause:
WHERE display='1'
WHERE display is the result of the coalesce.
Similarly I’d like to be able to do the same with something like this:
IF(ISNULL(gd.group_main_image),p.main_image,gd.group_main_image) AS image
... WHERE image IS NOT NULL
How can I do this please?
You can’t use aliases in the same level of query.
You must repeat yourself.
EDIT
Well, I’ve been too restrictive. You can use alias in an having clause in MySql. You can’t do that in other DBMS (Oracle, SQl Server). Generally it’s also not permitted in ANSI SQL.