Shadowing Posted August 5, 2012 Share Posted August 5, 2012 Hey guys i need to do a selection and not sure exactly how to do it. I need to select x,y from planets where alliance is equal to the same and x and y is also equal to the same so i have 15 rows for every x,y and im trying to see which set of 15 all share the same alliance name Link to comment https://forums.phpfreaks.com/topic/266692-wondering-how-to-select-this/ Share on other sites More sharing options...
awjudd Posted August 5, 2012 Share Posted August 5, 2012 Please show us your table structure. Should be a simple WHERE clause with an AND in it. ~awjudd Link to comment https://forums.phpfreaks.com/topic/266692-wondering-how-to-select-this/#findComment-1366871 Share on other sites More sharing options...
Shadowing Posted August 5, 2012 Author Share Posted August 5, 2012 ya but im comparing to a unpredetermind value for the where clause i want to select the x,y where all the alliances equal the same , and the x and y are the same so all 3 columns need to be the same duplicate the alliance column is blank in the example Link to comment https://forums.phpfreaks.com/topic/266692-wondering-how-to-select-this/#findComment-1366874 Share on other sites More sharing options...
Shadowing Posted August 5, 2012 Author Share Posted August 5, 2012 sounds confusing how im wording this lol im only wanting to select x1 y1 if all the columns that are x1 y1 all have the same alliance name but i need it to search each set of x and y so i cant just say select x,y from planets where x = 1 and y = 1 and alliance = "reavers" Link to comment https://forums.phpfreaks.com/topic/266692-wondering-how-to-select-this/#findComment-1366875 Share on other sites More sharing options...
DavidAM Posted August 5, 2012 Share Posted August 5, 2012 You can try this: SELECT x, y, COUNT(*) AS CountRows, COUNT(DISTINCT alliance) AS CountAlliance FROM planets WHERE x = y GROUP BY x, y HAVING CountRows = CountAlliance Unfortunately, it is not going to give you the alliance value. I may have misunderstood the requirements. This query returns rows where x = y. If you want any combination of x,y where all rows with that combination have the same alliance, you can take the WHERE clause out. This query is going to scan the entire table. So, the more data you have, the slower it will be. (depending on indexes, etc). Link to comment https://forums.phpfreaks.com/topic/266692-wondering-how-to-select-this/#findComment-1366909 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.