Forum Moderators: open

Message Too Old, No Replies

My SQL

Select Distinct

         

Alternative Future

12:13 pm on Mar 29, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hello to the forum,

MySQL version 4.0.23-standard

I want to retrieve results from my db that will not be duplicated in an instance of 2> matching results to the query.

My queryString will find all products matching the query, but in some instances there might be duplicate entries for a particular product. How I would identify this would be to check that only one instance of the product_id would be returned.

I had a look at distinct but not sure on how to complete the query to get all columns back from the db.

SELECT DISTINCT colum_product_id
FROM my_product_table
WHERE column_color = 'queryString'

(I think, please correct me if I am wrong)This would return all products that matches my queryString and only one instance of the product_id, so if I had many similar products with same colors I would only be shown one. But with this query I am only getting the product_id back with the query yeah? What would my query look like if I wanted the above query done but with other columns also returned so that my view has all details required?

TIA,

-george

PS - Again thanks for the replies to my last post, the suggestion works well...

mattglet

12:32 pm on Mar 29, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



SELECT (all your columns here)
FROM my_product_table
WHERE column_product_id IN
(
SELECT DISTINCT colum_product_id
FROM my_product_table
WHERE column_color = 'queryString'
)

Alternative Future

12:35 pm on Mar 29, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Thanks mattglet,

Just what I was after...

-George