mysql - SQL query distinct with additional select -


I need to do a query in the MySQL, which returns different values ​​for the product_id, but I want to enter the 'id' field There is a need to pick and return which is in the specific table.

- I will use it differently and I want to use it on product_id and see id

  SELECT DISTINCT id, product_id order_cart   

it will be easy to do on Pgsql But I do not know how to do it on mysql.

Your query is not well defined: Consider this table

  id product_id 1 1 2 2 3 1 4 2   

What should be the result of your query? If you mean

  id product_id 1 or 3 1 2 or 4 2   

You are in the country of non-determinative questions.

What can you do

  SELECT MIN (id), product_id order_cart GROUP BY product_id   

which will definitely arise

  id product_id 1 1 2 2    

Comments

Popular posts from this blog

Python SQLAlchemy:AttributeError: Neither 'Column' object nor 'Comparator' object has an attribute 'schema' -

java - How not to audit a join table and related entities using Hibernate Envers? -

mongodb - CakePHP paginator ignoring order, but only for certain values -