- Where Developers Learn, Share, & Build Careers
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
Post a Comment