Home  >  Q&A  >  body text

How to search title and use another column to check uniqueness

I have some scraped product data in the database and I want to use it on my website. I want to write a query that returns all items with the title "%EXAMPLE%" but only unique products.

The problem is that I have multiple rows for 1 item, and I only want to return 1 row per product (I'm scraping every day, so I get an extra row per item every day). The only difference between the rows is that they have another date and price, since that's the price history I'm looking for.

Example: We have 3 items: pink chocolate, pink apples and pink pears. There are 3 rows for each item because I scratched 3 times. For example (for the purpose of this example, I didn't add all the other columns):

Product ID title price Available
ABC123DEF PINK APPLE 0.47 1
ABC123DEF PINK APPLE 0.42 1
ABC123DEF PINK APPLE 0.41 1
ABC333FHG PINK PEAR 0.41 1
ABC333FHG PINK PEAR 0.41 1
ABC333FHG PINK PEAR 0.41 1
FH5845FJG pink chocolate 0.41 1
FH5845FJG pink chocolate 0.41 1
FH5845FJG pink chocolate 0.41 1

The result I want to get is:

Product ID title price Available
ABC123DEF PINK APPLE 0.47 1
ABC333FHG PINK PEAR 0.41 1
FH5845FJG pink chocolate 0.41 1

It seems I have to search for the title and then filter out the duplicate productIds in order to get the correct results. But I don't know how to do it.

Any ideas?

P粉244155277P粉244155277181 days ago393

reply all(1)I'll reply

  • P粉298305266
  • Cancelreply