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)
 SQL joins and performance

Author  Topic 

mattt
Posting Yak Master

194 Posts

Posted - 2001-11-14 : 09:39:07
Hi,
Anyone fancy helping me understand why these two SQL statements, which ought to return the same data set have such a huge performance difference that the returns records in about five seconds and the second one won't return any, even after an hour?

1) SELECT DISTINCT * FROM books
INNER JOIN authorsonbooks ON books.bookref = authorsonbooks.bookref
INNER JOIN authors ON authorsonbooks.authorID = authors.authorID WHERE
authors.authors LIKE '%adair%' OR authors.authorLName LIKE '%adair%'

2)SELECT DISTINCT * FROM books, authors, authorsonbooks
WHERE books.bookref = authorsonbooks.bookref AND authorsonbooks.authorID = authors.authorID
AND authors.authors LIKE '%adair%' OR authors.authorLName LIKE '%adair%'

if I can get awway without using the joins, building the query (from data entered into a form) is going to be an awful lot easier. Besides, I'm not sure how I can work more than one set of unrelated tables into a join.

   

- Advertisement -