alcoholic1 Posted October 21, 2007 Share Posted October 21, 2007 bassically i have a repeat region displaying all the data atm e.g IDS Names f1e162c2 death f5291b9f Rowger f6814a1f |MOB|B-DoGG f6814a1f demolition[RUS] f6814a1f Player0 f7f44761 frog f8e840a9 mob|roxygirl fb69016b «dolllars» now i wish to expand on this and only show ID's that have more than 1 entry. like it would the out put below from the above example f6814a1f |MOB|B-DoGG f6814a1f demolition[RUS] f6814a1f Player0 can it be done in a sql statement ? the current one is "SELECT * FROM guid ORDER BY IDS ASC" or do i have to make some kinda of php code that checks if theres is more than 1 of the same ID"S ??? Link to comment https://forums.phpfreaks.com/topic/74185-solved-group-similar-fields-and-display-corresponding-data/ Share on other sites More sharing options...
Wuhtzu Posted October 21, 2007 Share Posted October 21, 2007 Maybe something like: "SELECT id, count(id) FROM guid WHERE count(id)>1 GROUP BY id" Link to comment https://forums.phpfreaks.com/topic/74185-solved-group-similar-fields-and-display-corresponding-data/#findComment-374717 Share on other sites More sharing options...
alcoholic1 Posted October 21, 2007 Author Share Posted October 21, 2007 thx for the responce unforchantly when i try this a get a mysql error 1111 and output of invailed use of group function. i have tryed "SELECT id,name,count(*) as idgroups FROM guid GROUP BY id" but it groups simular together so only one is displayed Link to comment https://forums.phpfreaks.com/topic/74185-solved-group-similar-fields-and-display-corresponding-data/#findComment-374740 Share on other sites More sharing options...
alcoholic1 Posted October 21, 2007 Author Share Posted October 21, 2007 i just added more to the code above so it only displays once with more than 1 but still groups it all together. "SELECT guid,name,count(*) as idgroups FROM guid GROUP BY guid having count(guid) > 1" Link to comment https://forums.phpfreaks.com/topic/74185-solved-group-similar-fields-and-display-corresponding-data/#findComment-374747 Share on other sites More sharing options...
Barand Posted October 21, 2007 Share Posted October 21, 2007 SELECT g.IDS, g. names FROM guid g INNER JOIN (SELECT IDS, COUNT(*) as tot FROM guid GROUP BY IDS HAVING tot > 0) as X ON g.IDS = X.IDS Link to comment https://forums.phpfreaks.com/topic/74185-solved-group-similar-fields-and-display-corresponding-data/#findComment-374778 Share on other sites More sharing options...
alcoholic1 Posted October 21, 2007 Author Share Posted October 21, 2007 chears, good dam your a sql god lol thx man Link to comment https://forums.phpfreaks.com/topic/74185-solved-group-similar-fields-and-display-corresponding-data/#findComment-374800 Share on other sites More sharing options...
Barand Posted October 21, 2007 Share Posted October 21, 2007 The "... HAVING tot > 0" should, of course, be "... HAVING tot > 1" Link to comment https://forums.phpfreaks.com/topic/74185-solved-group-similar-fields-and-display-corresponding-data/#findComment-374918 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.