-1

I am using this line of SQL code:

SELECT DISTINCT tb_online.ip, tb_users.id, tb_online.login, tb_online.page 
FROM tb_online
JOIN tb_users 
  ON tb_online.login=tb_users.username 
ORDER BY login ASC

The problem is that this line ON tb_online.login=tb_users.username means that SQL query only selects users but not guests (they don't have username in the tb_users table).

How could I make SQL query to select both users and guests?

Paul T. Rawkeen
  • 3,994
  • 3
  • 35
  • 51
Lukas
  • 59
  • 7

1 Answers1

1

use left join:

SELECT DISTINCT tb_online.ip, tb_users.id, tb_online.login, tb_online.page 
FROM tb_online
LEFT JOIN tb_users 
  ON tb_online.login=tb_users.username 
ORDER BY login ASC
Jens
  • 67,715
  • 15
  • 98
  • 113