Switch0r Posted October 10, 2006 Share Posted October 10, 2006 Hey peeps, was wondering if anyone can help me. I'm trying to get a list of all distinct field pairs from a table i have (the table is listing artists in a cd collection if that makes any difference) and i have the first and second names that i want to get distinct values of.essentially i want to select a distinct pair of first and last, rather than just distinct last, as there may be crossover of the 2 names.eg:jeff buckleytim buckleyi want to select a distinct pair rather than just the last nameany ideas? Link to comment https://forums.phpfreaks.com/topic/23591-select-a-distinct-pair-of-fields/ Share on other sites More sharing options...
obsidian Posted October 10, 2006 Share Posted October 10, 2006 can you not just do a [i]SELECT DISTINCT lastname, firstname FROM table[/i]?seems like that should work for you. Link to comment https://forums.phpfreaks.com/topic/23591-select-a-distinct-pair-of-fields/#findComment-107112 Share on other sites More sharing options...
Switch0r Posted October 10, 2006 Author Share Posted October 10, 2006 doesn't that just select a distinct last name and a 'whatever' first name though?i want a distinct first/last combo Link to comment https://forums.phpfreaks.com/topic/23591-select-a-distinct-pair-of-fields/#findComment-107130 Share on other sites More sharing options...
obsidian Posted October 10, 2006 Share Posted October 10, 2006 not according to the manual... the following two are identical queries. play around with it and see what you get[code]SELECT DISTINCT c1, c2, c3 FROM t1 WHERE c1 > const;SELECT c1, c2, c3 FROM t1 WHERE c1 > const GROUP BY c1, c2, c3;[/code] Link to comment https://forums.phpfreaks.com/topic/23591-select-a-distinct-pair-of-fields/#findComment-107139 Share on other sites More sharing options...
fenway Posted October 10, 2006 Share Posted October 10, 2006 DISTINCT is _not_ a function! It is a modifier to SELECT, not to any of the columns. Generally, I use GROUP BY when I actually want to group things, and DISTINCT for uniqueness. Link to comment https://forums.phpfreaks.com/topic/23591-select-a-distinct-pair-of-fields/#findComment-107144 Share on other sites More sharing options...
Switch0r Posted October 10, 2006 Author Share Posted October 10, 2006 right, well I've checked what i've already got, and it turns out that you are all more than correct, and i already had what i wanted anyway.i feel sheepish, i'll baa all the way home now :) Link to comment https://forums.phpfreaks.com/topic/23591-select-a-distinct-pair-of-fields/#findComment-107193 Share on other sites More sharing options...
obsidian Posted October 11, 2006 Share Posted October 11, 2006 [quote author=fenway link=topic=111124.msg450175#msg450175 date=1160514295]DISTINCT is _not_ a function! It is a modifier to SELECT, not to any of the columns. Generally, I use GROUP BY when I actually want to group things, and DISTINCT for uniqueness.[/quote]fenway, i think i'm lost here. did i say something to instigate this argument about it being a function? i hope i didn't imply that it was :P Link to comment https://forums.phpfreaks.com/topic/23591-select-a-distinct-pair-of-fields/#findComment-107400 Share on other sites More sharing options...
fenway Posted October 11, 2006 Share Posted October 11, 2006 [quote author=obsidian link=topic=111124.msg450433#msg450433 date=1160572132]fenway, i think i'm lost here. did i say something to instigate this argument about it being a function? i hope i didn't imply that it was :P[/quote]Sorry about that, obsidian... I should have quoted this:[quote author=Switch0r link=topic=111124.msg450160#msg450160 date=1160512221]doesn't that just select a distinct last name and a 'whatever' first name though?[/quote]That's what triggered my response; your answer was entirely correct. Link to comment https://forums.phpfreaks.com/topic/23591-select-a-distinct-pair-of-fields/#findComment-107566 Share on other sites More sharing options...
obsidian Posted October 11, 2006 Share Posted October 11, 2006 [quote author=fenway link=topic=111124.msg450604#msg450604 date=1160596632]That's what triggered my response; your answer was entirely correct.[/quote]ok... good to know ;) thanks Link to comment https://forums.phpfreaks.com/topic/23591-select-a-distinct-pair-of-fields/#findComment-107574 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.