Welcome Guest, Not a member yet? Register   Sign In
Kinda stuck with database Joins...
#1

[eluser]Petsoukos[/eluser]
Hi,

I need some help figuring out how to Join a single column to a SQL result..

I have a table that contains comments... (id, user_id, comment, date.....)
and then I have a table that contains the users... (id, username, password, email...)

How can I retrieve the username only from the users table and attach it to the results of the comments with a single Query?

I was never good at MySQL Joins... I don't want to run a separate Query just to get the username...

Thanks!
#2

[eluser]Petsoukos[/eluser]
I hate it when I post a question and after a few minutes I come up with the solution by my self...

Sorry guys.. :red:


EDIT:
For anyone interested

Code:
SELECT c.*, u.username FROM `comments` AS c JOIN `users` AS u ON c.user_id = u.id


This attaches the column username (u.username) to the rest of the comments columns...

I'm not sure what kind of JOIN to use... but just JOIN works for now on my case.




Theme © iAndrew 2016 - Forum software by © MyBB