This should do what you want:
--I have a question which is probably really basic but can't work it out for the life of me so i thought i'll ask for some help. Below is a rough sketch of how my database is there are more details but principle is the same.
--In my database i have a table called "Meetings" & in my query i want to group all my meetings that are possible such as below.
--========= TEST DATA =============
declare @Meetings table ([DATE] Char(8), TypeOfMeeting Varchar(20), NameOfMeeting Varchar(10));
insert @Meetings values ( '20120801', 'private', 'Review' );
insert @Meetings values ( '20120801', 'private', 'Review' );
insert @Meetings values ( '20120801', 'group', 'Review' );
insert @Meetings values ( '20120801', 'group', 'Review' );
insert @Meetings values ( '20120801', 'group', 'Review' );
insert @Meetings values ( '20120801', 'Conference Call', 'Review' );
insert @Meetings values ( '20120801', 'Conference Call', 'Review' );
select * from @Meetings;
/*
DATE | TypeOfMeeting | NameOfMeeting
20120801 private Review
20120801 private Review
20120801 group Review
20120801 group Review
20120801 group Review
20120801 Conference Call Review
20120801 Conference Call Review
*/
--========= SOLUTION =============
-- Use 2 selects, 1 grouped for [TypeofMeeting] <> 'private',
-- & 1 not grouped for [TypeofMeeting] = 'private', & UNION them together.
-- NOTE: You MUST use UNION ALL, or duplicate rows are removed from the result set -
-- so only 1 'private' would appear.
SELECT
[DATE],
[TypeofMeeting],
[NameofMeeting]
FROM
@meetings
WHERE [TypeofMeeting] <> 'private'
GROUP BY
[DATE],
[TypeofMeeting],
[NameofMeeting]
UNION ALL
SELECT
[DATE],
[TypeofMeeting],
[NameofMeeting]
FROM
@meetings
WHERE [TypeofMeeting] = 'private'
/*
Only thing is in "TypeOfMeeting" i have the options of
- Group
- Conference Call
- Private
I want to group all the meetings except "Private" so if i have the same Date,TypeOfMeeting,NameofMeeting
for Group or Conference Call they should all be groups for people involved. However if its Private
then it should not be grouped and all the Private meetings should be seperated.
So the expected result should be:
DATE | TypeOfMeeting | NameOfMeeting
20120801 private Review
20120801 private Review
20120801 group Review
20120801 Conference Call Review
How do i ignore private from the group by results?
*/