Doing a two-tabled query

Please support our MS SQL advertiser: Intel Parallel Studio Home
Reply

Join Date: Dec 2008
Posts: 25
Reputation: Tonkz is an unknown quantity at this point 
Solved Threads: 0
Tonkz Tonkz is offline Offline
Light Poster

Doing a two-tabled query

 
0
  #1
Apr 22nd, 2009
For example you want two tables that have a column that has an identical id and that id you want to print out in another table. how will you code it?
Reply With Quote Quick reply to this message  
Join Date: Apr 2009
Posts: 818
Reputation: Airshow is on a distinguished road 
Solved Threads: 116
Airshow's Avatar
Airshow Airshow is offline Offline
Practically a Posting Shark

Re: Doing a two-tabled query

 
0
  #2
Apr 22nd, 2009
Tonkz,

Oh boy, you're going to have fun. You're about to learn all about SQL joins. Look them up in the MS SQL manual (w3schools provides a reasonable primer).

In short, there's no unique answer to your question. It depends on which type of join is appropriate to your tables and the particular query you are trying to compose, which itself depends on the way in which your data is normaisled into tables and how the tables are keyed.

Have fun

Airshow
Reply With Quote Quick reply to this message  
Join Date: Dec 2008
Posts: 25
Reputation: Tonkz is an unknown quantity at this point 
Solved Threads: 0
Tonkz Tonkz is offline Offline
Light Poster

Re: Doing a two-tabled query

 
0
  #3
Apr 23rd, 2009
Oh I read about that, but it seems that I was doing it wrong my code doesn't work. Maybe I should have posted it. Well i'll post it tomorrow hopefull too sleepy to do it now =.= by the way, you're right it was fun!!!
Reply With Quote Quick reply to this message  
Join Date: Apr 2009
Posts: 217
Reputation: mail2saion is an unknown quantity at this point 
Solved Threads: 31
mail2saion's Avatar
mail2saion mail2saion is offline Offline
Posting Whiz in Training

Re: Doing a two-tabled query

 
0
  #4
Apr 23rd, 2009
SELECT TABLE1.*,TABLE2.* FROM TABLE1 INNER JOIN TABLE2
ON TABLE1.ID=TABLE2.ID

NOW EXAMINE THE RESULT. CHANGE INNER word by LEFT,RIGHT,FULLER..........
MARK AS SOLVED if its help you.

REGARDS
MCTS - Shawpnendu bikash maloroy
http://shawpnendu.blogspot.com
Reply With Quote Quick reply to this message  
Join Date: May 2007
Posts: 146
Reputation: Stylish is an unknown quantity at this point 
Solved Threads: 14
Stylish's Avatar
Stylish Stylish is offline Offline
Junior Poster

Re: Doing a two-tabled query

 
0
  #5
Apr 23rd, 2009
Inner Join (id is foreign key)
  1. SELECT *
  2. FROM table1 t1, table2 t2
  3. WHERE t1.id = t2.id

Left Outer Join (id is foreign key)
  1. SELECT *
  2. FROM table1 t1, table2 t2
  3. WHERE t1.id *= t2.id
I NEED AN ADULT!
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the MS SQL Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC