[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 366
  • Last Modified:

add a where clause to existing query to limit results because I have numerous staff members

please see answer which worked if only using data from one staff member this_user='staff3'
http://www.experts-exchange.com/Database/MySQL/Q_28318002.html#a39718372

SELECT
        profile_id, this_user
FROM a_messages
GROUP BY
        profile_id
HAVING sum(CASE WHEN sender = 'staff3' and this_user='staff3' THEN 1 ELSE 0 END) = 0
 where this_user='staff3' 

Open in new window


I am getting results from profile_id that had messages from other staff1,staff2 and no messages from staff3

so I am trying to add a where clause


Error Code: 1064. You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'where this_user='staff3'' at line 7
0
rgb192
Asked:
rgb192
1 Solution
 
Daniel WilsonCommented:
the WHERE clause belongs before the GROUP BY

SELECT
        profile_id, this_user
FROM a_messages
 where this_user='staff3' 
GROUP BY
        profile_id
HAVING sum(CASE WHEN sender = 'staff3' and this_user='staff3' THEN 1 ELSE 0 END) = 0

Open in new window


I'm not sure that does what you're asking, but it corrects the syntax error.
0
 
rgb192Author Commented:
Yes this corrects the syntax error.

Thanks
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now