2 Replies - 436 Views - Last Post: 02 May 2013 - 02:19 AM

#1 Keylogger  Icon User is offline

  • D.I.C Regular

Reputation: 6
  • View blog
  • Posts: 340
  • Joined: 14-February 11

SQL Inner Join not working

Posted 30 April 2013 - 09:57 AM

I have the following users:

ID | FirstName | LastName
1 John Doe
2 Maria Carey
3 Leonel Messi

And the following clients:

ID | userOpen | userShutdown
1 1 3
2 3 2
3 3 3
4 1 1
5 2 2

So, it differs the users who open from the users who gives shutdown.
SELECT clients.ID, users.FirstName + ' ' + users.LastName
FROM clients
INNER JOIN users AS A ON A.ID = clients.userOpen 
INNER JOIN users AS B ON B.ID = clients.Shutdown
ORDER BY clients.ID DESC

How can I retrieve:

ID | userOpen | userShutdown
1 | Jonh Doe | Leonel Messi
2 | Leonel Messi | Maria Carey
3 | Leonel Messi | Leonel Messi
4 | John Doe | John Doe
5 | Maria Carey | Maria Carey
?
Thanks!

Is This A Good Question/Topic? 0
  • +

Replies To: SQL Inner Join not working

#2 modi123_1  Icon User is offline

  • Suitor #2
  • member icon



Reputation: 8390
  • View blog
  • Posts: 31,200
  • Joined: 12-June 08

Re: SQL Inner Join not working

Posted 30 April 2013 - 10:04 AM

Just use left joins and it should be fine.
Was This Post Helpful? 1
  • +
  • -

#3 Keylogger  Icon User is offline

  • D.I.C Regular

Reputation: 6
  • View blog
  • Posts: 340
  • Joined: 14-February 11

Re: SQL Inner Join not working

Posted 02 May 2013 - 02:19 AM

Thank you..it worked fine with LEFT JOINs.
SELECT clients.ID, users.FirstName + ' ' + users.LastName
FROM clients
LEFT JOIN users AS A ON A.ID = clients.userOpen 
ORDER BY clients.ID DESC


Was This Post Helpful? 0
  • +
  • -

Page 1 of 1