Home > other >  Exclude condition in result
Exclude condition in result

Time:08-24

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.

CodePudding user response:

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.

  • Related