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 2005 Forums
 Transact-SQL (2005)
 Using EXISTS instead INNER JOIN

Author  Topic 

paradise_wolf
Starting Member

32 Posts

Posted - 2007-02-21 : 09:03:32
How to use EXISTS instead INNER JOIN in the below procedure ?

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ALTER PROCEDURE GetProductsOnPromotInDep
(
@DepartmentID INT
)
AS

SET NOCOUNT ON

SELECT DISTINCT Product.ProductID,
Title
FROM Product
INNER JOIN ProductCategory ON ProductCategory.ProductID = Product.ProductID
INNER JOIN Category ON Category.CategoryID = ProductCategory.CategoryID
INNER JOIN Department ON Department.DepartmentID = Category.DepartmentID
WHERE Category.DepartmentID = @DepartmentID
AND Product.OnPromotion = 1
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-02-21 : 09:05:05
you have to explain what you want the query to do ?


KH

Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-02-21 : 09:13:34
This is a continuation from http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=79441


Peter Larsson
Helsingborg, Sweden
Go to Top of Page

paradise_wolf
Starting Member

32 Posts

Posted - 2007-02-21 : 09:22:52
Hi khtan and Peso

{{you have to explain what you want the query to do ?}}

I want to get the list of products that obey these conditions, collect them in a DataTable and display them in a DataList control in a web page ( C# )whenever the user clicks a button.

Regarding the SQL database tables, there is a relation of “one to many” between 'Department' and 'Category', “one to many” between 'Category' and 'ProductCategory', “many to one” between 'ProductCategory' and 'Product'.
Go to Top of Page

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2007-02-21 : 10:08:31
The main question here is WHY YOU WANT TO DO IT?

Just to know it can be done or you are facing some performance problem with your existing query or something else?

Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page

paradise_wolf
Starting Member

32 Posts

Posted - 2007-02-21 : 11:00:45
{{The main question here is WHY YOU WANT TO DO IT?

Just to know it can be done or you are facing some performance problem with your existing query or something else?}}

Not really, Harsh.

I don’t even deployed the web site yet ( actually I don’t even finish it ) but since I was told that using “EXISTS” is better ( probably for performance reasons ) and I am still learning SQL, it would be wise to learn how to use a code for best performance. That is why I want to learn it.
Go to Top of Page
   

- Advertisement -