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

  • Home
  • SEARCH
  • 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 8738473
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T10:44:14+00:00 2026-06-13T10:44:14+00:00

If this is a stupid question, forgive me, I’m not very familiar with PostgreSQL.

  • 0

If this is a stupid question, forgive me, I’m not very familiar with PostgreSQL.

I’ve collected inventory data from used car dealerships in my area and stored it in a postgreSQL table. I’ve got a second table with particular details regarding certain makes and models. For example:

The dealership table is structured like so:

-----------------------------------------
| Dealership | Make | Model | Year | ID |
----------------------------------------|
|     A      | Ford | F250  | 2003 |  1 |
|     A      | Chevy| Cobalt| 2005 |  2 |
|     B      | Ford | F250  | 2003 |  1 |
|     B      | Dodge| Chrgr | 2012 |  3 |
-----------------------------------------

The details table is structured like so:

-----------------------------------------
|     ID     | DetailA| DetailB| DetailC|
-----------------------------------------
|     1      |  data  |  data  |  data  |
|     2      |  data  |  data  |  data  |
|     3      |  data  |  data  |  data  |
|     4      |  data  |  data  |  data  |
-----------------------------------------

My goal is to retrieve vehicle matches from multiple dealerships and display the appropriate details. In the above example, I would like to see:

-----------------------------------------------------
| Make | Model | Year | DetailA | DetailB | DetailC |
-----------------------------------------------------
| Ford | F250  | 2003 |   data  |  data   |  data   |
-----------------------------------------------------

With this result, I will know that both A and B havea 2003 Ford F250 for sale, and can view the related details of the vehicle.

I’ve tried many different queries, but most are variations on something like this:

SELECT DISTINCT
    dealership_table.make,
    dealership_table.model,
    dealership_table.year
            details_table.detaila,
            details_table.detailb,
            details_table.detailc
FROM
    dealership_table
INNER JOIN
    details_table
    ON
    dealership_table.id = details_table.id
WHERE
     dealership_table.dealership = 'A'
     OR
     dealership_table.dealership = 'B'

However this returns all of the distinct matches from the table where dealership is either A or B. I’ve tried multiple inner-joins, but I an error complaining details_table is specified multiple times.

If I’m doing something really silly, I apologize. Like I said before, I’m pretty much an SQL noob.

What am I doing wrong? How should I go about retrieving the desired results? Any suggestions, solutions, or advice is greatly appreciated!

  • 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-13T10:44:15+00:00Added an answer on June 13, 2026 at 10:44 am

    You can write:

    SELECT dealership_table1.make,
           dealership_table1.model,
           dealership_table1.year,
           details_table.detaila,
           details_table.detailb,
           details_table.detailc
      FROM dealership_table dealership_table1
      JOIN dealership_table dealership_table2
        ON dealership_table1.make  = dealership_table2.make
       AND dealership_table1.model = dealership_table2.model
       AND dealership_table1.year  = dealership_table2.year
      JOIN details_table
        ON dealership_table.id = details_table.id
     WHERE dealership_table1.dealership = 'A'
       AND dealership_table1.dealership = 'B'
    ;
    

    (Note that the FROM dealership_table dealership_table1 and JOIN dealership_table dealership_table2 set up distinct “aliases”, so you can use the same table multiple different times in the same query without getting name-conflicts.)

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

Sidebar

Related Questions

Forgive me if this is a stupid question. I am not very experienced with
I'm used to MSSQL, not Mysql, so sorry for this probably stupid question. I'm
I'm kinda new to rails so forgive if this is a stupid question. The
I am a Scala novice so forgive me if this is a stupid question,
I'm not too great with xdebug so forgive me if this is a stupid
Forgive me if this is a particularly stupid question! mysql_query($query) returns a boolean, but
Forgive me if this is a really stupid question, but how do I get
Forgive me if my question is stupid, but I'm not a web programmer and
Forgive me if this is a stupid question. I'm a bit new to mobile
Forgive me if this is a stupid question, I know there have been similar

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.