php - mysql request from two tables when one is empty -
i have 2 tables. , request return me 0 rows if second table empty , first - isn't... how can solve problem?
table: users
id username name email 1 myuname myname myemail@domain.com
table: accounts
customerid phone params 1 +1111 null
my sql request below:
select a.phone, a.params, u.email, u.username, u.name `account` a, `users` u a.customerid = u.id limit 1';
the request above return 0 rows if account table empty , users table isn't... how can solve problem? thanks.
you can use left join:
select a.phone, a.params, u.email, u.username, u.name `account` left join `users` u on a.customerid = u.id limit 1
a left join select rows first table , rows on second table matches. if there no match, u.email, u.username , u.name null.
Comments
Post a Comment