-1

I've tried to look, but I can't get a query working.

I have a table called 'replies' and a table called 'users'. 'Replies' had a column called 'used_ID'. I need to get everything from 'replies' and the 'username' of the 'id' 'user_ID'.

This is what I tried:

SELECT *.replies, users.username
FROM replies * left join users username
    on users.id=replies.added_by

I have to make it in one query, but I just don't know how.

jarlh
  • 42,561
  • 8
  • 45
  • 63
TKTurbo
  • 92
  • 1
  • 11

1 Answers1

1

Try this-

SELECT r.*, 
u.username
FROM replies r 
LEFT JOIN users u
on u.id=r.added_by
Ajan Balakumaran
  • 1,639
  • 1
  • 8
  • 16
mkRabbani
  • 16,295
  • 2
  • 15
  • 24
  • Thank you! .added_by had to be r.user_id but it works now. But why do I need to have r and u instead of replies and users? – TKTurbo May 14 '19 at 09:26
  • That's just alias and not required. You can also use table names directly. – mkRabbani May 14 '19 at 09:30
  • For more details that why we should use table/column alias, you can visit this link- https://stackoverflow.com/questions/198196/when-to-use-sql-table-alias – mkRabbani May 14 '19 at 09:41