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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T21:26:51+00:00 2026-06-17T21:26:51+00:00

Why this query return with error of duplicate id? I’m using php SELECT DISTINCT

  • 0

Why this query return with error of duplicate id? I’m using php

SELECT DISTINCT * FROM products  as prd
    LEFT OUTER JOIN  (SELECT DISTINCT * FROM product_aliases) AS product_aliases
    ON product_aliases.product_id = prd.id 
    AND product_aliases.alias = '$alias'

    LEFT OUTER JOIN  (SELECT DISTINCT * FROM product_images as prdim
        LEFT OUTER JOIN  product_image_votes as prdimvt 
            ON prdimvt.product_image_id = prdim.id) AS productimages 
    ON productimages.product_id = prd.id 
WHERE prd.id = $id

ERROR:

Database Error Error: SQLSTATE[42S21]: Column already exists: 1060
Duplicate column name ‘id’ SQL Query: SELECT DISTINCT * FROM products
as prd LEFT OUTER JOIN (SELECT DISTINCT * FROM product_aliases) AS
product_aliases ON product_aliases.product_id = prd.id AND
product_aliases.alias = ‘Pringles The Original’ LEFT OUTER JOIN
(SELECT DISTINCT * FROM product_images as prdim LEFT OUTER JOIN
product_image_votes as prdimvt ON prdimvt.product_image_id = prdim.id)
AS productimages ON productimages.product_id = prd.id WHERE prd.id = 1

  • 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-17T21:26:53+00:00Added an answer on June 17, 2026 at 9:26 pm

    You have 3 tables in your query and it is possible at least 2 of them have the same column id. Using * in your select would select all columns in these three tables selecting id multiple times

    You could solve this by specifying the columns using the alias

    SELECT DISTINCT prd.id, prd.Name FROM products  as prd
    LEFT OUTER JOIN  (SELECT DISTINCT * FROM product_aliases) AS product_aliases
    ON product_aliases.product_id = prd.id 
    AND product_aliases.alias = '$alias'
    ... rest of your query here
    

    You could also do

    SELECT DISTINCT prd.* FROM products  as prd
    

    if you don’t want to list them one by one

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

Sidebar

Related Questions

I am trying to return voice messages from a database using this query :
I'm getting a weird return when executing this query : SELECT * FROM rrp
Let say that we have the following query: SELECT DISTINCT COUNT(`users_id`) FROM `users_table`; this
how set distinct to this query return _dataContext.ProjectPictures.Include(Projects).Include(ProjectPictureTypes).Where(p => p.ProjectPictureTypes.Id == 1).ToList(); i need
Can anyone explain why this query returns an empty result. SELECT * FROM (`bookmarks`)
I have a SELECT query like this: SELECT id_default_value, id_type FROM ntg_attribute, ntg_module_attribute WHERE
I am using this query: public IEnumerable.....{ var query = from d in Context.Documentos
Possible Duplicate: Reference - What does this error mean in PHP? In the following
I'm trying to get the IsAdmin Value with SQL query(This query return 1 line
I expect this FQL query to return a non-empty array, because there are comments

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.