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.
Author |
Topic |
rnelsch
Starting Member
31 Posts |
Posted - 2012-06-14 : 17:57:19
|
I'm trying to create a query from multiple tables and I know how the Inner Joins work, but for some reason in my query the data is only pulling from 1 table and not both. For example, some records show on both Table A and Table B, but Table B will have records that are not included on Table A. When I create the inner joins it seems to limit only records that on Table A. Is there some type of syntax or query language I can use to make sure it includes all the data from both tables outside of Inner Joins? Table A - Holds all Jobs (whether they are created from a phone call, sales call, booked directly, etc) Table B - Hold only Jobs that are created from Phone CallsWhen I add Table B, it limits the return to only data found on Table B. I need all the data to show, but only 1 field from Table B, and when I add that field it limits the number of records to only those found on Table B.Yes, I'm a noob, I know but I'm the only one in the office with even the slightest idea of how to write a SQL query. I figured an Inner Join would return data from both tables, is it possible I'm missing a field in my Joins?Ryan A Nelsch |
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
rnelsch
Starting Member
31 Posts |
Posted - 2012-06-15 : 09:59:34
|
That definitely helps, can I use both Inner and Outer joins?Ryan A Nelsch |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
rnelsch
Starting Member
31 Posts |
Posted - 2012-06-15 : 12:55:11
|
Here is what I have so far, without Inner Joins. I only used the Left join for Fields I want to see that are shared on both tablesSelect Job.JobID, Job.ProjectID, Job.LocationID, Job.JobClass, Job.JobType, Job.Department, Job.SchedDate, Job.TotalTicket, PhoneCall.LeadSource, PhoneCall.IsNewLocationFrom JobLeft Join PhoneCallOn Job.JobID = PhoneCall.ForJobID and Job.LocationID = PhoneCall.LocationID and Job.JobClass = PhoneCall.JobClass and Job.Department = PhoneCall.Department and Job.JobType = PhoneCall.JobTypeFYI - There are more fields that are shared in each table, do I need to create a Join for each field or can I do it only for the ones I want to view? Ryan A Nelsch |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
rnelsch
Starting Member
31 Posts |
Posted - 2012-06-15 : 13:20:53
|
I gotcha. Now what about joining three tables. How would I use a Outer join with three tables?Ryan A Nelsch |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
|
|
|
|