Solved

query - combine two into one dataset

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
How to leverage one TLS certificate to encrypt Microsoft SQL traffic and Remote Desktop Services, versus creating multiple tickets for the same server.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

744 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now