Jump to content


Photo

COUNT and GROUP BY from multiple columns...


  • Please log in to reply
2 replies to this topic

#1 emexinc

emexinc
  • Members
  • PipPipPip
  • Advanced Member
  • 34 posts

Posted 26 August 2006 - 08:45 AM

...i've come close to answers, but nothing that has worked thus far...

...firstly i want to search a mysql database...
...but i need to search multiple columns...
...but i do not want duplications, so if two or more results are the same, i would like that to only be counted as one result...

...here's what i'm looking at...i have a mysql database with artist names, first and last...and i currently have four sets of these ( i've only come across four artists max thus far for one song with the songs that i have )...and i'd like to have the total number of artists beginning with the letter 'A' ( for example ) whether it be their first or last name that would start with that...but i do not want to the same artist counted more than once even if they have their name under multiple songs...any direction would be great...i'm sorta out of ideas at this point...thanks

#2 Zane

Zane
  • Administrators
  • Advanced Member
  • 4,134 posts

Posted 26 August 2006 - 08:55 AM

Try this
SELECT CONCAT(firstname, ' ', lastname) As fullname FROM database GROUP BY fullname

btn_donate_SM.gif Want to thank me? Contribute to my PayPal piggy-bank
 

172938.png

#3 fenway

fenway
  • Staff Alumni
  • MySQL Si-Fu / PHP Resident Alien
  • 16,199 posts
  • LocationToronto, ON

Posted 28 August 2006 - 10:08 PM

Depending on what you're using this for, DISTINCT could also work:

SELECT DISTINCT firstname, lastname FROM database

Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users