Select multiple tables when one table is empty in MySQL

前端 未结 5 1451
萌比男神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:04

    The query mentioned above display join of both tables if a contain 2 record and b contain 7 records it displays 7*2 = 14 records. In your case one of the table is empty( with 0 records), it will not display any data. If still you want to display data and tables are not having any relationship, you need to check if count of both tables greater that 0. Otherwise display records from only one table which is not empty.

提交回复
热议问题