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 7888623
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T05:52:45+00:00 2026-06-03T05:52:45+00:00

I noticed when doing a query with multiple JOINs that my query didn’t work

  • 0

I noticed when doing a query with multiple JOINs that my query didn’t work unless I gave one of the table names an alias.

Here’s a simple example to explain the point:

This doesn’t work:

SELECT subject
from items
join purchases on items.folder_id=purchases.item_id
join purchases on items.date=purchases.purchase_date
group by folder_id

This does:

SELECT subject
from items
join purchases on items.folder_id=purchases.item_id
join purchases as p on items.date=p.purchase_date
group by folder_id

Can someone explain this?

  • 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-03T05:52:46+00:00Added an answer on June 3, 2026 at 5:52 am

    You are using the same table Purchases twice in the query. You need to differentiate them by giving a different name.

    You need to give an alias:

    • When the same table name is referenced multiple times

    Imagine two people having the exact same John Doe. If you call John, both will respond to your call. You can’t give the same name to two people and assume that they will know who you are calling. Similarly, when you give the same resultset named exactly the same, SQL cannot identify which one to take values from. You need to give different names to distinguish the result sets so SQL engine doesn’t get confused.

    Script 1: t1 and t2 are the alias names here

    SELECT      t1.col2
    FROM        table1 t1
    INNER JOIN  table1 t2
    ON          t1.col1 = t2.col1
    
    • When there is a derived table/sub query output

    If a person doesn’t have a name, you call them and since you can’t call that person, they won’t respond to you. Similarly, when you generate a derived table output or sub query output, it is something unknown to the SQL engine and it won’t what to call. So, you need to give a name to the derived output so that SQL engine can appropriately deal with that derived output.

    Script 2: t1 is the alias name here.

    SELECT col1
    FROM
    (
        SELECT col1
        FROM   table1
    ) t1
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have noticed that doing actions like implementing an interface, that a small rectangle
While doing some experiment on serialization, I noticed that my object name is lost
We are doing a conversion of Crystal Reports to SSRS. One thing we noticed
I'm working on a database program and I noticed that when I'm doing queries
i've got this stored procudure that won't work. If I try this query in
I have been doing some mobile web app testing and have noticed that the
When doing some web maintenance today, I noticed a strange new folder on my
Once again I'm doing Java graphics (Graphics2D) but I noticed there is no Polygon.Double
I am doing some computation in Java and it worked fine but I noticed
I notice a strange thing during doing some stored procedures I can explain that

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.