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
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Which join type

Author  Topic 

Mondeo
Constraint Violating Yak Guru

287 Posts

Posted - 2007-07-17 : 12:41:09
I have this

SELECT t1.capid, t2.cvehicle_mantext, t2.cvehicle_modtext, t2.cvehicle_dertext
FROM dbStock..tblVehicles t1 JOIN
PUB_CAR..CapVehicles t2
ON t1.capid = t2.cvehicle_id
WHERE t1.noimage = 1
ORDER BY t2.cvehicle_mantext, t2.cvehicle_modtext, t2.cvehicle_dertext

I've just used JOIN but its returning odd results, I want to return all the vehicles in the tblVehicles Table and any matches from CapVehicles

Which join to use?

Thanks

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2007-07-17 : 12:43:34
inner join seems about right. you just have to join on the proper columns.

_______________________________________________
Causing trouble since 1980
blog: http://weblogs.sqlteam.com/mladenp
Go to Top of Page

rudesyle
Posting Yak Master

110 Posts

Posted - 2007-07-17 : 12:51:50
quote:
Originally posted by Mondeo

I have this

SELECT t1.capid, t2.cvehicle_mantext, t2.cvehicle_modtext, t2.cvehicle_dertext
FROM dbStock..tblVehicles t1 JOIN
PUB_CAR..CapVehicles t2
ON t1.capid = t2.cvehicle_id
WHERE t1.noimage = 1
ORDER BY t2.cvehicle_mantext, t2.cvehicle_modtext, t2.cvehicle_dertext

I've just used JOIN but its returning odd results, I want to return all the vehicles in the tblVehicles Table and any matches from CapVehicles

Which join to use?

Thanks



If you need to return ALL vehicles, even if the have no matches in the CapVehicles table, then you will need to use an OUTER JOIN
Go to Top of Page
   

- Advertisement -