Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7715349
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T02:21:44+00:00 2026-06-01T02:21:44+00:00

I have a problem to get to SQL queries into one, the problem is

  • 0

I have a problem to get to SQL queries into one, the problem is that I want FirstName, LastName twice. First the names from tblUploadedImages and then the names from tblImageParticipants

ALTER PROCEDURE GetFeaturedImages
AS
BEGIN
   SELECT 
       tblUser.FirstName AS FirstNameUploader, 
       tblUser.LastName AS LastNameUploader, 
       tblUser.UserID AS UserIDUploader 
   FROM 
       tblUploadedImages 
   INNER JOIN 
       tblUser ON tblUploadedImages.UserID = tblUser.UserID

   SELECT        
        tblUploadedImages.ImgUrl, 
        tblUploadedImages.ImgUrlOriginal, 
        tblUploadedImages.Description, 
        tblUploadedImages.ImageID, 
        tblUser.FirstName, 
        tblUser.LastName, 
        tblUploadedImages.UserID AS Uploader, 
        tblImageParticipants.UserID AS Participants
   FROM            
        tblImageParticipants  
   INNER JOIN
        tblUploadedImages ON tblImageParticipants.ImageID = tblUploadedImages.ImageID
   INNER JOIN
        tblUser ON tblImageParticipants.UserID = tblUser.UserID
   ORDER BY 
        tblUploadedImages.Added
END

I get the right results its just that I want it in one SQL query. How can I do that?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T02:21:47+00:00Added an answer on June 1, 2026 at 2:21 am

    I think you are looking for a UNION ALL. A UNION removes the duplicates. What I think you want is not to remove the duplicates.

    SELECT 
       tblUser.FirstName AS FirstNameUploader, 
       tblUser.LastName AS LastNameUploader, 
       tblUser.UserID AS UserIDUploader 
    FROM 
       tblUploadedImages 
    INNER JOIN 
       tblUser ON tblUploadedImages.UserID = tblUser.UserID
    
    UNION ALL
    
    SELECT        
        tblUser.FirstName, 
        tblUser.LastName, 
        tblUploadedImages.UserID AS Uploader
    FROM            
        tblImageParticipants  
    INNER JOIN
        tblUploadedImages ON tblImageParticipants.ImageID = tblUploadedImages.ImageID
    INNER JOIN
        tblUser ON tblImageParticipants.UserID = tblUser.UserID
    ORDER BY 
        tblUploadedImages.Added
    

    It might also be a god idé to have something so you know which is which. You can add an additional column for that like this:

    SELECT 
       tblUser.FirstName AS FirstNameUploader, 
       tblUser.LastName AS LastNameUploader, 
       tblUser.UserID AS UserIDUploader,
       'UploadedImages' AS Type
    FROM 
       tblUploadedImages 
    INNER JOIN 
       tblUser ON tblUploadedImages.UserID = tblUser.UserID
    
    UNION ALL
    
    SELECT        
        tblUser.FirstName, 
        tblUser.LastName, 
        tblUploadedImages.UserID AS Uploader,
        'ImageParticipants' AS Type
    FROM            
        tblImageParticipants  
    INNER JOIN
        tblUploadedImages ON tblImageParticipants.ImageID = tblUploadedImages.ImageID
    INNER JOIN
        tblUser ON tblImageParticipants.UserID = tblUser.UserID
    ORDER BY 
        tblUploadedImages.Added
    

    I hope this helps

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have one problem , I want to get some data from XML file
i have a problem. i want to get info about my string have other
Afternoon Developers, I have a problem that's beginning to get on my wick. I
I'm terribly bad at keeping MySQL queries straight, but that aside I have one
I have a problem with a recursive SQL function. The original problem is that
I'm new in SQL queries. I have a problem with the query. I have
I have 2 sql queries in my code where the second one is wrapped
So we have multiple stored procs that get used during a morning SQL job
I have a series of T-SQL queries that I use that are running very
I have a problem to get the values and text of the MultiSelectList to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.