Skip to content
Advertisement

I need to list the only latest versions of the products with php – mysql

I’m just trying to list the only latest versions of the products. Not all versions with the same product name.

So this: enter image description here

Instead of this: enter image description here

*tables are not so important I just want the code to get the data.
*tables are not so important I just want the code to get the data.

This is my code but lists nothing :

JavaScript

My product table:

enter image description here

Advertisement

Answer

One option is to filter with a subquery:

JavaScript

If you are running MySQL 8.0, you can also use rank():

JavaScript

This assumes that product_id uniquely identifies each product (so your table would have several rows per product_id) – if that’s not the case, use product_name instead.

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement