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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T22:00:38+00:00 2026-06-12T22:00:38+00:00

My MySQL query keeps creating duplicate entries. I think it is to do with

  • 0

My MySQL query keeps creating duplicate entries. I think it is to do with my join or ID values.
I am new to JOIN and I am trying to do a fairly simple JOIN and filter.

Basically I am filtering products on a product listing page.

newCatCols

+----+-----------------+-------------+
| id | sku             | name        |
+----+-----------------+-------------+  
|  1 | 670_apple       | Black       |
|  2 | 670_apple       | Apple       |
|  3 | 670_apple       | Blush       |
|  4 | 670_apple       | Turquoise   |
|  5 | 670_apple       | Light Coral |
| 10 | 640_apple_black | Apple_Black |
| 22 | 347_blush       | Lime        |
| 33 | 347_blush       | Turquoise   |
| 44 | 347_blush       | Gray        |
| 55 | 347_blush       | Yellow      |
+----+-----------------+-------------+

newCatProds

+----+-----------------+--------+------+
| id | sku             | cost   | cat  |
+----+-----------------+--------+------+    
|  1 | 670_apple       | 489.55 | swar |
| 10 | 640_apple_black | 458.99 | swar |
| 22 | 347_blush       | 741.44 | sig  |
+----+-----------------+--------+------+    

If the custom chooses Black, I want it to return colours with Black, and Apple_Black and Apple. It just duplicates listings though:

// productslisting.php?cat=swar&filter=Black
$strColourGet=mysql_real_escape_string($_GET["filter"]);
$strCatGet=mysql_real_escape_string($_GET["cat"]);  

if($strColourGet=="Black"){

$checkSQL=mysql_query("
SELECT * FROM `newCatProds`
INNER JOIN `newCatCols`
ON `newCatProds`.`sku` = `newCatCols`.`sku`
WHERE (
    `name` = 'Black' OR
    `name` = 'Apple' OR
    `name` = 'Apple_Black' 
)
AND `status`='1' AND `category` = '".$strCatGet."'
ORDER BY `newCatProds`.`rank` DESC");

}

Results appear twice though. Can I somehow not have it appear twice?

710     702_appleblack  139         sig     0   8   1   1   1243    702_appleblack  Apple_Black
486     613_turq    139         sig     0   124     1   1   695     613_turq    Black
463     379_sapphire2   139         sig     0   46  1   1   652     379_sapphire2   Black
504     670_apple   119         sig     0   176     1   1   607     670_apple   Black
463     379_sapphire2   139         sig     0   46  1   1   658     379_sapphire2   Apple_Black

So maybe a group? So the 379_sapphire2 should only appear ONCE as it has both in?

  • 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-12T22:00:40+00:00Added an answer on June 12, 2026 at 10:00 pm

    Those are all distinct results. Look at them more closely.

    If you want to avoid this, instead of SELECT * FROM do a specific field(s) request.

    To get only one answer, you need to specify that field in select as distinct and create a group_by clause. You can’t create a group by with * in select parameters.

    PS: I would suggest you rewrite your query something like this. It is easier to understand that way:

    SELECT
        DISTINCT( category )
    FROM
        newCatProds p
    JOIN
        newCatCols c
    ON
        p.sku = c.sku
    WHERE
        c.name IN ( 'Black', 'Apple', 'Apple_Black' )
        AND status =  1
        AND category = '" . $strCatGet . "'
    GROUP BY
        category
    ORDER BY
        p.rank DESC;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here is my MySQL Query that im trying to execute. it keeps failing with
this is the mysql query SELECT * FROM users AS up JOIN users AS
I have the following mysql query, which is producing a list of entries by
I'm having trouble creating a join in the codeigniter format, i have a MySQL
I want to query a MySQL database. I have the following. $name keeps changing
So basicly what I'm trying to accomplish is that foreach row in mysql query
I've got a simple SQL query that keeps throwing an SQL syntax error. It
Mysql query question How to count as 1 if is 1,2 or 5 for
MySQL Query works fine using MySQL workbench but produces an error when I am
Mysql query returns result like this collector amount name 1 0.00 gihan 1 2000.00

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.