Jump to content

grouping in query


shaddf

Recommended Posts

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

Link to comment
Share on other sites

"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 by shaddf
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.