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
 Query over multiple tables

Author  Topic 

lallejoe
Starting Member

5 Posts

Posted - 2011-02-23 : 08:40:57
Hy
I need to get some specific data from totally 8 tables. I made the following query:

select
device.name as devicename, device.description as devicedescription, typemodel.name as phonetyp, userid, numplan.dnorpattern as number, numplan.description as numberdescription, callingsearchspace.name as linecss, pickupgroup.name as pickupgroup
from
device, typemodel, enduser, numplan, callingsearchspace, pickupgrouplinemap, pickupgroup, devicenumplanmap
where
device.tkmodel = typemodel.enum
and
device.fkenduser = enduser.pkid
and
numplan.fkcallingsearchspace_sharedlineappear = callingsearchspace.pkid
and
numplan.pkid = pickupgrouplinemap.fknumplan_line
and
pickupgrouplinemap.fkpickupgroup = pickupgroup.pkid
and
device.pkid = devicenumplanmap.fkdevice
and
devicenumplanmap.fknumplan = numplan.pkid

This query works.
But as a result, i only get entries where all fields contains data. But there are a lot of fields which do not have, for example, a enduser entry.
What can i do, that i get all fields?

robvolk
Most Valuable Yak

15732 Posts

Posted - 2011-02-23 : 10:10:09
Look in SQL Server Books Online for LEFT JOIN and use that syntax to join tables, instead of joining them in the WHERE clause.
Go to Top of Page
   

- Advertisement -