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
 problem with join

Author  Topic 

sqlnewbie82
Starting Member

11 Posts

Posted - 2007-10-22 : 08:44:19
i have a problem with joining two tables. i am comparing to see if the package id exists in the other table and then it prints out the package name in the other table

but i am getting this error, is there anything wrong with my sql statement

i am getting this error
Syntax error. in query expression '(select Package_name from 11Package where 11Package.Package_id = 12Package_Listing.Package_id)'

this is my sql query
select * , (select Package_name from 11Package where 11Package.Package_id = 12Package_Listing.Package_id) as Package_name from 12Package_Listing

regards

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2007-10-22 : 08:51:55
[code]Select t1.* , t2.Package_name
from 12Package_Listing t1 JOIN 11Package t2
on t2.Package_id = t1.Package_id[/code]

Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-10-22 : 08:59:40
As I told you in the other thread you need to use [] around the table names if they dont start with alphabet

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-10-22 : 09:23:17
And to wrap things up
SELECT		t12.*,
t11.Package_Name
FROM [12Package_Listing] AS t12
LEFT JOIN [11Package] AS t11 ON t11.Package_ID = t12.Package_ID



E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

sqlnewbie82
Starting Member

11 Posts

Posted - 2007-10-22 : 09:30:14
thanks alot i managed to do it :)
Go to Top of Page
   

- Advertisement -