Solved

query - combine two into one dataset

Posted on 2011-03-22
5
417 Views
Last Modified: 2012-05-11
I have to queries...The first shows a main image the second shows a thumb.. how could i combine these into one dataset? The thumb fields could get name with a thumb postfex

      SELECT [IMAGE_NAME],[IMAGE_DATA]
        FROM [Store].[dbo].[Products] P
          LEFT JOIN [Store].[dbo].[Images] I ON p.Product_Image = I.Image_ID  
           WHERE Product_ID = @Product_ID

        
        SELECT [IMAGE_NAME],[IMAGE_DATA]
         FROM [Store].[dbo].[Products] P
          LEFT JOIN [Store].[dbo].[Images] I ON p.Product_Thumb = I.Image_ID  
           WHERE Product_ID = @Product_ID
0
Comment
Question by:vbnetcoder
5 Comments
 
LVL 26

Expert Comment

by:tigin44
ID: 35191342


SELECT [IMAGE_NAME],I1.[IMAGE_DATA],I2.[IMAGE_DATA]
        FROM [Store].[dbo].[Products] P
          LEFT JOIN [Store].[dbo].[Images] I1 ON p.Product_Image = I1.Image_ID  
          LEFT JOIN [Store].[dbo].[Images] I2 ON p.Product_Thumb = I2.Image_ID  
           WHERE Product_ID = @Product_ID

       
0
 
LVL 19

Expert Comment

by:Rikin Shah
ID: 35191387
SELECT [IMAGE_NAME],[IMAGE_DATA]
FROM [Store].[dbo].[Products] P
LEFT JOIN [Store].[dbo].[Images] I ON p.Product_Image = I.Image_ID  
LEFT JOIN [Store].[dbo].[Images] I ON p.Product_Thumb = I.Image_ID  
WHERE Product_ID = @Product_ID
0
 

Author Comment

by:vbnetcoder
ID: 35191507
I have a thumb image AND a main image, Product_Image is the id for the main image and Product_Thumb is the image for the sub...

This dataset needs to show BOTH

So, i shoulid have 2 [IMAGE_NAME] AND [IMAGE_DATA] fielld one for the main and one for the thumb
0
 
LVL 40

Accepted Solution

by:
Sharath earned 500 total points
ID: 35191947
you mean this?
SELECT I1.[IMAGE_NAME] Main_Image_Name, 
       I1.[IMAGE_DATA] Main_Image_Data, 
       I2.[IMAGE_NAME] Sub_Image_Name, 
       I2.[IMAGE_DATA] Sub_Image_Data 
  FROM [Store].[dbo].[Products] P 
       LEFT JOIN [Store].[dbo].[Images] I1 
         ON p.Product_Image = I.Image_ID 
       LEFT JOIN [Store].[dbo].[Images] I2 
         ON p.Product_Thumb = I.Image_ID 
 WHERE P.Product_ID = @Product_ID

Open in new window

0
 

Author Closing Comment

by:vbnetcoder
ID: 35192067
ty
0

Featured Post

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

If you find yourself in this situation “I have used SELECT DISTINCT but I’m getting duplicates” then I'm sorry to say you are using the wrong SQL technique as it only does one thing which is: produces whole rows that are unique. If the results you a…
This article describes how to use the timestamp of existing data in a database to allow Tableau to calculate the prior work day instead of relying on case statements or if statements to calculate the days of the week.
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question