Query 2 SQL tables bring all results

1

I am doing a SQL query to bring users, but I consult 2 tables: users and users_vip

No users have all users and users_vip only those that are vip (active or not).

When I make my query joining the 2 tables it only brings who has a registration in vip, because I use the WHERE u.id = uv.iduser, the query looks like this:

SELECT uv.status, u.id, u.name, u.username, u.email, uv.datapedido, uv.dataconfirm, uv.datafinal
FROM euk_users u, euk_users_vip uv
WHERE u.id = uv.iduser

If I have 10 regular users and 1 VIP, the query will only bring this 1 VIP.

I wanted to query it also bring users who are in users but are not in users_vip, with missing data blank, at zero, or something like that. How can I do this?

    
asked by anonymous 03.05.2018 / 15:04

1 answer

3

You can do this using LEFT JOIN , which will return everything you have in the right-hand table and what you have in the left table for example:

SELECT 
    uv.status, 
    u.id, u.name, 
    u.username, 
    u.email, 
    uv.datapedido, 
    uv.dataconfirm, 
    uv.datafinal
FROM euk_users u
LEFT JOIN euk_users_vip uv
ON u.id = uv.iduser;
    
03.05.2018 / 15:11