Solved

query - combine two into one dataset

Posted on 2011-03-22
5
418 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

Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

Question has a verified solution.

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

In this article I will describe the Copy Database Wizard method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.

808 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