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
 Joining records in tables

Author  Topic 

duf
Starting Member

39 Posts

Posted - 2012-01-03 : 09:25:25
When I join two tables all records are linked in these tables. Is it possible to connect only one record from the table number one with one record of table number two? Of course, if and only if the conditions are met to join tables.

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2012-01-03 : 09:32:38
can you give any examples?


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-01-03 : 10:51:30
quote:
Originally posted by duf

When I join two tables all records are linked in these tables. Is it possible to connect only one record from the table number one with one record of table number two? Of course, if and only if the conditions are met to join tables.


It depends on how you're joining tables
if joining without any condition, it causes all records to be linked to form a cartesian product. If you specify condition, it will do the join only based on condition.

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

duf
Starting Member

39 Posts

Posted - 2012-01-03 : 13:50:41
For example:

first table IDCN
CNID...CN
001....6001
002....5201
003....4810

second table IDDATA
ID...DATA...CNID
1....Aaaa...001
2....Bbbb...002
3....Cccc...003

Joining:
SELECT CN, DATA FROM IDCN, IDDATA WHERE IDCN.CNID=IDDATA.CNID

RESULT INQUIRY:
CN....DATA
6001..Aaaa
5201..Bbbb
4810..Cccc

All data from two tables are combined. Can I get just the result of combining a single record from two tables? I would like to obtain only just like this result of combining:
CN....DATA
5201..Bbbb
Can I identify which records are to be connected?
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2012-01-03 : 13:58:57
HOW.....

Are we suppose to KNOW that you want that ONE

Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx


Want to help yourself?

http://msdn.microsoft.com/en-us/library/ms130214.aspx

http://weblogs.sqlteam.com/brettk/

http://brettkaiser.blogspot.com/


Go to Top of Page

sunitabeck
Master Smack Fu Yak Hacker

5155 Posts

Posted - 2012-01-03 : 13:59:25
[code]SELECT CN, DATA FROM IDCN, IDDATA WHERE IDCN.CNID=IDDATA.CNID
AND IDCN.CN=5201[/code]

or a similar clause that limits the data to the row(s) that you are interested in.
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2012-01-03 : 14:04:46
quote:
Originally posted by sunitabeck

SELECT CN, DATA FROM IDCN, IDDATA WHERE IDCN.CNID=IDDATA.CNID
AND IDCN.CN=5201


or a similar clause that limits the data to the row(s) that you are interested in.



BRILLIANT!!!!

Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx


Want to help yourself?

http://msdn.microsoft.com/en-us/library/ms130214.aspx

http://weblogs.sqlteam.com/brettk/

http://brettkaiser.blogspot.com/


Go to Top of Page

sunitabeck
Master Smack Fu Yak Hacker

5155 Posts

Posted - 2012-01-03 : 14:16:16
quote:
BRILLIANT!!!!

Brett

Brett! Happy New Year to you too!!
Go to Top of Page
   

- Advertisement -