943,553 Members | Top Members by Rank

Ad:
  • MS SQL Discussion Thread
  • Unsolved
  • Views: 671
  • MS SQL RSS
Apr 22nd, 2009
0

Doing a two-tabled query

Expand Post »
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?
Similar Threads
Reputation Points: 10
Solved Threads: 0
Light Poster
Tonkz is offline Offline
25 posts
since Dec 2008
Apr 22nd, 2009
0

Re: Doing a two-tabled query

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
Sponsor
Reputation Points: 300
Solved Threads: 357
WiFi Lounge Lizard
Airshow is offline Offline
2,522 posts
since Apr 2009
Apr 23rd, 2009
0

Re: Doing a two-tabled query

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!!!
Reputation Points: 10
Solved Threads: 0
Light Poster
Tonkz is offline Offline
25 posts
since Dec 2008
Apr 23rd, 2009
0

Re: Doing a two-tabled query

SELECT TABLE1.*,TABLE2.* FROM TABLE1 INNER JOIN TABLE2
ON TABLE1.ID=TABLE2.ID

NOW EXAMINE THE RESULT. CHANGE INNER word by LEFT,RIGHT,FULLER..........
Reputation Points: 26
Solved Threads: 44
Posting Whiz in Training
mail2saion is offline Offline
247 posts
since Apr 2009
Apr 23rd, 2009
0

Re: Doing a two-tabled query

Inner Join (id is foreign key)
MS SQL Syntax (Toggle Plain Text)
  1. SELECT *
  2. FROM table1 t1, table2 t2
  3. WHERE t1.id = t2.id

Left Outer Join (id is foreign key)
MS SQL Syntax (Toggle Plain Text)
  1. SELECT *
  2. FROM table1 t1, table2 t2
  3. WHERE t1.id *= t2.id
Reputation Points: 44
Solved Threads: 19
Junior Poster
Stylish is offline Offline
148 posts
since May 2007

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in MS SQL Forum Timeline: datetime format in ms sql
Next Thread in MS SQL Forum Timeline: Problem in update query





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC