0

In Mariadb 10.5.8 I have a table with some repeating value e.g.

Item , qty
shoes 3
pants 2
pants 2
pants 4 
shoes 3
pants 2
shoes 6
pants 2
shoes 3
pants 2

I want to query up to 3 occurrences of each Item. so it will return

Item , qty
shoes 3
pants 2
pants 2
pants 4
shoes 3
shoes 6

Note it stopped picking each item (shoes, pants) after picking the first 3 occurances.

4
  • 2
    I would use the row_number window function and partition by "Item". Mar 14, 2021 at 15:11
  • Please provide the output of SHOW CREATE TABLE xyz\G; for your table. You have, for example, 4 entries of pants 2 in one field (AIUI) - without being able to distinguish between them, those values are, to all intents and purposes, useless - unless they're (for example) daily sales without a timestamp and you have a very primitive (manual?) POS system - and you want a SUM() or similar? What's the rationale behind getting the first three and not the fourth? Mar 14, 2021 at 15:29
  • See the tag I added.
    – Rick James
    Mar 15, 2021 at 0:20
  • It would be more help if you provide an exact output you want. Mar 15, 2021 at 6:44

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.