Jump to content

[SOLVED] selecting multple doubles


mforan

Recommended Posts

I can be more specific but I have to invent an example. I'm not sure how relevant this is to your situation. Anyway, it's a two-for-price-of-one offer

 

Prices data

[pre]

+----------+-------+

| price_id | price |

+----------+-------+

|        1 | 29.95 |

|        2 | 35.00 |

|        3 | 25.00 |

|        4 | 25.00 |

|        5 | 20.00 |

|        6 | 15.00 |

|        7 | 15.00 |

|        8 | 12.00 |

|        9 | 10.50 |

+----------+-------+[/pre]

 

Find rows with the same prices.

 

[pre]

mysql> SELECT a.price_id as itemA, b.price_id as itemB

    -> FROM prices a INNER JOIN prices b ON a.price=b.price

    -> WHERE a.price_id < b.price_id;

+-------+-------+

| itemA | itemB |

+-------+-------+

|    3 |    4 |

|    6 |    7 |

+-------+-------+

[/pre]

 

Find rows with duplicate prices

 

[pre]

mysql> SELECT p.price_id

    -> FROM prices p

    -> JOIN (SELECT price, COUNT(*) FROM prices GROUP BY price

    -> HAVING COUNT(*) > 1) as x

    -> ON p.price=x.price;

+----------+

| price_id |

+----------+

|        3 |

|        4 |

|        6 |

|        7 |

+----------+

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.