Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Return primary key even when foreign key is empty

Author  Topic 

monaya
Yak Posting Veteran

58 Posts

Posted - 2015-02-20 : 16:55:16
Hey guys, I have a query that returns contacts connected to a client, but the problem is that it's only returning a result when a contact is associated with a client, even if the client does exist in the db. i want it to still return the client if the client exists.

SELECT * FROM clients, addressbook where clients.clientid = addressbook.clientid AND (clients.clientname LIKE '" . strtoupper($_GET['txtfname'])."%')

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2015-02-20 : 17:00:47
SELECT *
FROM clients
LEFT JOIN addressbook ON clients.clientid = addressbook.clientid
WHERE clients.clientname LIKE '" . strtoupper($_GET['txtfname'])."%'

Tara Kizer
SQL Server MVP since 2007
http://weblogs.sqlteam.com/tarad/
Go to Top of Page
   

- Advertisement -