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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T02:19:53+00:00 2026-05-20T02:19:53+00:00

Just playing with OpenCarts DB to see if I can lear something. If I

  • 0

Just playing with OpenCarts DB to see if I can lear something.
If I use the following SELECT the result returns duplicated rows:

SELECT DISTINCT
p.product_id AS pid,
p.model AS modelo,
SUBSTRING(p.model,1,25) AS substr_modelo,
p.image AS foto,
p.price AS preco,
pd.name AS nome,
cd.name AS category
FROM product p
LEFT JOIN product_description pd ON p.product_id = pd.product_id
LEFT JOIN product_to_category p2c ON p.product_id = p2c.product_id
LEFT JOIN category_description cd ON p2c.category_id = cd.category_id
WHERE pd.name LIKE _utf8 'laser%' collate utf8_unicode_ci
ORDER BY p.product_id DESC

Note that even using DISTINCT it is duplicated, but if I add an GROUP BY p.product_id it stops duplicating the rows. Is it the best solution?

  • 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-05-20T02:19:53+00:00Added an answer on May 20, 2026 at 2:19 am

    DISTINCT removes duplicate entire rows.

    Use GROUP BY p.product_id to display one 1 row per product id.

    Note: If you group by product_id, if you have multiple product description’s, multiple categories, or multiple category description’s The query will return a random row for each. Use the MIN() or MAX() functions to retrieve single ID’s, or use the GROUP_CONCAT() function to retrieve all the description.

    Example

    SELECT
      p.product_id AS pid,
      p.model AS modelo,
      SUBSTRING(p.model,1,25) AS substr_modelo,
      p.image AS foto,
      p.price AS preco,
      GROUP_CONCAT(pd.name) AS nome,
      GROUP_CONCAT(cd.name) AS category
    FROM product p
      LEFT JOIN product_description pd ON p.product_id = pd.product_id
      LEFT JOIN product_to_category p2c ON p.product_id = p2c.product_id
      LEFT JOIN category_description cd ON p2c.category_id = cd.category_id
      WHERE pd.name LIKE _utf8 'laser%' collate utf8_unicode_ci
    GROUP BY p.product_id
    ORDER BY p.product_id DESC
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Have just started playing with ASP.NET MVC and have stumbled over the following situation.
I've just started playing with Django and am loosely following the tutorial with my
So I was playing around the other day just to see exactly how mass
So, when playing with the development I can just set settings.DEBUG to True and
Just playing around with some of the APIs in .NET and I can't seem
I was just playing around with ckeditor and can't get the darn thing to
I'm just playing with signal in Mac OS X. Why does the following code
Just playing around with the now released Silverlight 2.0. I'm trying to put a
I'm just playing around and I'm trying to grab information from websites. Unfortunately, with
I have just started playing with the ASP.Net MVC framework, and today I created

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.