merging two SELECT queries

后端 未结 2 1162
南笙
南笙 2021-02-10 03:45

I am either getting old or the queries that I need to write are getting more and more complicated. The following query will get all the tasks associated with the us

2条回答
  •  情深已故
    2021-02-10 04:20

    I'd probably use a UNION.

    SELECT `date`
       FROM `tasks` WHERE `user_id`=1
    UNION
    SELECT `t1`.`date`
       FROM `tasks` `t1`
       INNER JOIN `urls` `u1` ON `u1`.`id` = `t1`.`url_id`
       WHERE `u1`.user_id`=1;
    

提交回复
热议问题