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 2000 Forums
 SQL Server Development (2000)
 Simple query question

Author  Topic 

Goalie35
Yak Posting Veteran

81 Posts

Posted - 2005-12-30 : 11:00:35
Ok, just a quick query question....

I have two tables: TCustomers & TMobile.
-TCustomers contains ALL customer data.
-TMobile contains a bunch of data pertaining to a customers cell phone if they choose for us to send them info to their mobile phones.
-Not all customers have a row in TMobile and no customer can have more than 1 row each in TMobile.

Ok, so with that said, I'm looking to create a simple query that returns ALL rows from the TCustomers table, regardless of whether or not that customer has a row in TMobile AND I want to append the mobile phone number (TMobile.mobileNum) from the TMobile table to the end of each row for those who have one.

I tried doing this with an inner join but that excludes customers without a row in the TMobile table. How could I do this?

Thanks in advance.

-Goalie35

i_love_techno
Starting Member

4 Posts

Posted - 2005-12-30 : 12:28:11
instead of inner join, use "left outer join".

ur best bet with a question like this is to read thru some sql books, they will help you out alot, I promise! :)


Find happiness in listening to your discontent.
Go to Top of Page

Goalie35
Yak Posting Veteran

81 Posts

Posted - 2005-12-30 : 13:32:28
Ooops, never mind. I made a stupid mistake.

Yeah, I had originally tried a left outer join and still couldn't get it to work in my Query Analyzer which is why I posted my problem here.

Turns out there was an error in my WHERE clause that forced zero rows to be returned. Thanks for your help though.

-Goalie35
Go to Top of Page

shallu1_gupta
Constraint Violating Yak Guru

394 Posts

Posted - 2006-01-01 : 22:58:16
Use left Outer join as rightly said.
Select TCustomers.*,TMobile.mobileNum from TCustomers left outer join TMobile
on TCustomers.CustomerId = TMobile.CustomerId
Go to Top of Page
   

- Advertisement -