Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Exclude condition in result

How do i exclude the condition in the Result?
I just want Table_A.id to be shown.

The query:

SELECT 
    Table_A.id,
    IF(Table_B.bbb > NOW(),
        Table_A.aaa,
        Table_B.bbb)
    AS to_order
FROM
    Table_A
        LEFT JOIN
    Table_B ON Table_A.id = Table_B.table_a_id
ORDER BY to_order DESC;

All suggestions appreciated.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You can move your condition to the ORDER BY-section and it should work.
Your query would look something like that:

SELECT 
Table_A.id
FROM
    Table_A
        LEFT JOIN
    Table_B ON Table_A.id = Table_B.table_a_id
ORDER BY 
    IF(Table_B.bbb > NOW(),
        Table_A.aaa,
        Table_B.bbb)
    AS to_order DESC;

See also this post.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading