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 |

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.