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.
| Author |
Topic |
|
gjerstad
Starting Member
1 Post |
Posted - 2003-09-08 : 12:13:27
|
| Fellas,I'm a beginner using MS SQL 2000 wondering how the hell JOIN works. The code wotks fine, I just need some theory!The code below required that I add DISTINCT on my web server because it would return duplicate rows. My localserver didn't require DISTINCT alltogether.SELECT DISTINCT Title, C.[Name] AS CategoryFROM News_Stories AS N LEFT OUTER JOIN News_Categories AS C ON N.CategoryID = C.CategoryIDSo I'm wondering how does the join ever duplicate the rows in the first place? What is the process' steps to return dups?Dupped,Kim in Dr Congo |
|
|
X002548
Not Just a Number
15586 Posts |
Posted - 2003-09-08 : 12:46:01
|
It's a relational thing...I would think that a news category may have 1 to many news stories..If it's possible that a title is not defined as the primary key of new stories, you would then allow "duplicates". But are they really?For example, check out:USE NorthwindGoSELECT * FROM OrdersWHERE OrderId = 10248SELECT * FROM Orders l INNER JOIN [Order Details] r ON l.OrderId = r.OrderIdWHERE l.OrderId = 10248GO In the second query it appears there are duplcates, but they are the parental rows related to the details...1 to many...Brett8-)SELECT @@POST=NewId()That's correct! It's an AlphaNumeric! |
 |
|
|
|
|
|