Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to select more then one field using the DISTINCT keyword

Status
Not open for further replies.

diezy

Technical User
Sep 2, 2002
50
CA
hey

i was wondering if there is a way to select more then on field using the DISTINCT keyword

i have a query like this:
$str_sql = "SELECT id, product_id, name, description, price FROM products ORDER BY name ASC";

However i know adding the Distinct keyword like this won't work

$str_sql = "SELECT id, product_id, DISTINCT(name), description, price FROM products ORDER BY name ASC";


any help would be appreciated

thanks
 
Have you tried:

$str_sql = "SELECT DISTINCT name, id, product_id, description, price FROM products ORDER BY name ASC";?

That syntax works for me...

[cheers]
Cheers!
Laura
 
actually it got it to work like this

$str_sql = "SELECT id, product_id, name, description, price FROM products GROUP BY name ORDER BY name ASC";
 
oh really eh?...i just read the clip.
ok i have this product table, full of 10 products records (let just say) now each product belongs to a category. However, there are some products that are in more the one category. So really there are 30 product records in the the products table. So, on the site there is a link for ALL categories. So, what i want when ppl click on the link is to show all the unique products in the products table.

Now heres the thing....there is more then one column in the products table that has the same data

for instance:

id product_id name cost category
1 b_013 big_basket 13.00 weddings
2 b_013 big_basket 13.00 weddings
1 b_014 baby_basket 6.00 baby
2 b_014 baby_basket 6.00 baby

 
sorry my i entered in my data wrong

however please this me is this is wrong too and how i should go it correctly

id product_id name cost category
1 b_013 big_basket 13.00 weddings
2 b_013 big_basket 13.00 weddings
3 b_014 baby_basket 6.00 baby
4 b_014 baby_basket 6.00 baby


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top