shaddf Posted March 2, 2017 Share Posted March 2, 2017 how can I make this query bring results grouped by Team_cat? here it brings all results select f0.*,positions.job_title,Cat.Team_catId ,Cat.Team_cat from soka_staff_details_tbl as f0 join soka_staff_job_tbl as f1 on f1.staff_id=f0.staff_id JOIN soka_job_title_tbl AS positions ON positions.job_id = f1.job_id JOIN Soka_team_category_tbl AS Cat ON Cat.Team_catId = f1.Team_catId where Cat.Team_catId <> '1' ; +----------+--------+---------------+-------+-------------+--------+----------+-----------------+---------------+-----------+-------------+-------+-----------+------+-----------+---------+---------------------+--------------------+------------+----------+ | staff_id | Fname | Lname | D_O_B | Nationality | Gender | D_O_JOIN | playedfor_clubs | Managed_clubs | Telephone | Mobilephone | email | thumbnail | img | biography | honours | date_created | job_title | Team_catId | Team_cat | +----------+--------+---------------+-------+-------------+--------+----------+-----------------+---------------+-----------+-------------+-------+-----------+------+-----------+---------+---------------------+--------------------+------------+----------+ | 1 | Alfred | reza | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | 2017-03-01 15:10:29 | Manager | 2 | FIRST | | 2 | Aram | Kauma | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | 2017-03-01 15:10:29 | First-team coach | 2 | FIRST | +----------+--------+---------------+-------+-------------+--------+----------+-----------------+---------------+-----------+-------------+-------+-----------+------+-----------+---------+---------------------+--------------------+------------+----------+ 2 rows in set (0.98 sec) but here it brings 1 record select f0.*,positions.job_title,Cat.Team_catId ,Cat.Team_cat from soka_staff_details_tbl as f0 join soka_staff_job_tbl as f1 on f1.staff_id=f0.staff_id JOIN soka_job_title_tbl AS positions ON positions.job_id = f1.job_id JOIN Soka_team_category_tbl AS Cat ON Cat.Team_catId = f1.Team_catId where Cat.Team_catId <> '1' GROUP BY Cat.Team_catId; +----------+--------+---------------+-------+-------------+--------+----------+-----------------+---------------+-----------+-------------+-------+-----------+------+-----------+---------+---------------------+-----------+------------+----------+ | staff_id | Fname | Lname | D_O_B | Nationality | Gender | D_O_JOIN | playedfor_clubs | Managed_clubs | Telephone | Mobilephone | email | thumbnail | img | biography | honours | date_created | job_title | Team_catId | Team_cat | +----------+--------+---------------+-------+-------------+--------+----------+-----------------+---------------+-----------+-------------+-------+-----------+------+-----------+---------+---------------------+-----------+------------+----------+ | 1 | Alfred | reza | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | 2017-03-01 15:10:29 | Manager | 2 | FIRST | +----------+--------+---------------+-------+-------------+--------+----------+-----------------+---------------+-----------+-------------+-------+-----------+------+-----------+---------+---------------------+-----------+------------+----------+ 1 row in set (0.11 sec) yet it has to bring two under Team_cat FIRST Quote Link to comment Share on other sites More sharing options...
requinix Posted March 2, 2017 Share Posted March 2, 2017 "Grouping by" something means combining all the records with the same values together. That means there will be only one row per Team_catId. You do not want to do a GROUP BY. What kind of results are you trying to get? Quote Link to comment Share on other sites More sharing options...
shaddf Posted March 2, 2017 Author Share Posted March 2, 2017 (edited) "Grouping by" something means combining all the records with the same values together. That means there will be only one row per Team_catId. You do not want to do a GROUP BY. What kind of results are you trying to get? iam trying to get Alfred| aram |first both these to display in category first. so that i can have a heading FIRST CATEGORY and then list the names below it.when using php to display the data. HOW CAN I GET THIS RECORDSET IN SQL FOR THAT END RESULT Edited March 2, 2017 by shaddf Quote Link to comment Share on other sites More sharing options...
requinix Posted March 3, 2017 Share Posted March 3, 2017 If you're trying to make it display a certain way then the database isn't the issue. Moved. What's your current code to display the names? Quote Link to comment Share on other sites More sharing options...
Jacques1 Posted March 3, 2017 Share Posted March 3, 2017 Sounds like shaddf is mixing up GROUP BY and ORDER BY. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.