Select multiple tables when one table is empty in MySQL

前端 未结 5 1448
萌比男神i
萌比男神i 2020-12-10 06:37

I\'m trying to do

SELECT * FROM a, b

However, it doesn\'t return anything if one of the tables is empty. How do I make it so it returns \'a

5条回答
  •  無奈伤痛
    2020-12-10 07:03

    You should do a left join.

    Like this

    SELECT *
    FROM A
     LEFT JOIN B ON A.ID = B.ID
    

    Then you receive the rows in A and the respective row in B if exists.

提交回复
热议问题