Advertisement

02.18.2000 at 08:47AM PST, ID: 10297440
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

7.6

Question for mayhew - Joining Tables On A Query

Asked by John500 in MS SQL Server

How can I join two queries into one.

I have two different queries and need to link them on the 'Store' field.

Query 1:
SELECT Stores.Store, StoreStatus, StoreType, Computer
From Stores, StoreDetails
WHERE Stores.Store = StoreDetails.Store
AND EXISTS (SELECT Parts.Part_ID
From Parts, PartDetails, TempStorage
WHERE Parts.Part_ID = PartDetails.Part_ID
AND Parts.Part_ID = TempStorage.Part_ID)

Query 2:
SELECT Store, PartName, PartNumber, PartType, InStock
From Parts, PartDetails, TempStorage
WHERE Parts.Part_ID = PartDetails.Part_ID
AND Parts.Part_ID = TempStorage.Part_ID

Response by mayhew:

Your first query is using EXISTS incorrectly.  I assume you want a list of stores that have parts in stock.

You need to include a reference to your main query in your sub query.
Otherwise you'll just get back everything from your main query as if you had no sub query in your where clause.

As far as linking them goes, you can do it by defining your two queries as tables and joining them.

select * from
(SELECT Stores.Store, StoreStatus, StoreType, Computer
From Stores, StoreDetails
WHERE Stores.Store = StoreDetails.Store
AND EXISTS (SELECT *
From Parts, PartDetails, TempStorage
WHERE Parts.Part_ID = PartDetails.Part_ID
AND Parts.Part_ID = TempStorage.Part_ID
AND Parts.Store = Stores.Store)) a,
(SELECT Store, PartName, PartNumber, PartType, InStock
From Parts, PartDetails, TempStorage
WHERE Parts.Part_ID = PartDetails.Part_ID
AND Parts.Part_ID = TempStorage.Part_ID) b
where a.store = b.store










Start Free Trial
 
Loading Advertisement...
 
[+][-]02.18.2000 at 09:44PM PST, ID: 2537570

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]02.22.2000 at 10:49AM PST, ID: 2547391

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: MS SQL Server
Sign Up Now!
Solution Provided By: mayhew
Participating Experts: 2
Solution Grade: A
 
 
[+][-]02.22.2000 at 09:35PM PST, ID: 2549149

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]02.23.2000 at 06:13AM PST, ID: 2550465

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20081119-EE-VQP-49