MySQL Forums
Forum List  »  Newbie

If statement in fields
Posted by: Wim Roffel
Date: November 22, 2016 06:03AM

If have the following code

SELECT field1, field2, field3, IF((SELECT so.id_order FROM `ps_orders` so WHERE so.id_customer = c.id_customer) > 0, 0, 1) as new FROM ps_orders o LEFT JOIN ps_customer c ON c.id_customer=o.id_customer WHERE new=1

The problem is in that "IF((SELECT so.id_order FROM `ps_orders` so WHERE so.id_customer = c.id_customer) > 0, 0, 1) as new" field. If I have no where statement everything works ok and if I do "$row=mysqli_fetch_array()" I can access the field as "$row['new']". However, the "WHERE new=1" clause is not accepted.

How can I solve that?

Options: ReplyQuote


Subject
Written By
Posted
If statement in fields
November 22, 2016 06:03AM
November 22, 2016 06:39AM
November 22, 2016 01:08PM
November 22, 2016 02:54PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.