DISTINCT

C++, C#, Java, PHP, ect...
Post Reply
User avatar
hallsofvallhalla
Site Admin
Posts: 12026
Joined: Wed Apr 22, 2009 11:29 pm

DISTINCT

Post by hallsofvallhalla »

Don't know why I had trouble with this but thought I would share

if you ever need to select a field only once yu can use DISTINCT.

so lets say you have a DB with a table for a auction full of items and many of them are the same item.

Lets say you want to list all items in the auction but not repeat all the ones that are the same

select DISTINCT name, seller from auction

works like a charm. Most of you may already know this, I had known of that keyword. Thought I would share. :P
User avatar
Jackolantern
Posts: 10891
Joined: Wed Jul 01, 2009 11:00 pm

Re: DISTINCT

Post by Jackolantern »

I read about it in the huge PHP/MySQL book I read, and while it sounds very useful, outside of reporting I have not had a need for it yet in PBBG development. For reporting it is indispensable, as it eliminates a ton of extra PHP code to get the same effect.
The indelible lord of tl;dr
User avatar
hallsofvallhalla
Site Admin
Posts: 12026
Joined: Wed Apr 22, 2009 11:29 pm

Re: DISTINCT

Post by hallsofvallhalla »

yep, i am actually using it for a reporting site I am building for work.
Post Reply

Return to “Coding”