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

Posted on 2013-12-14
Last Modified: 2013-12-14
please see answer which worked if only using data from one staff member this_user='staff3'

        profile_id, this_user
FROM a_messages
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
Question by:rgb192
LVL 32

Accepted Solution

Daniel Wilson earned 500 total points
ID: 39718824
the WHERE clause belongs before the GROUP BY

        profile_id, this_user
FROM a_messages
 where this_user='staff3' 
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.

Author Closing Comment

ID: 39718971
Yes this corrects the syntax error.


Featured Post

Zoho SalesIQ

Hassle-free live chat software re-imagined for business growth. 2 users, always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
How do i connect MySQL on Visual Studio 3 54
mySQL 5.7 table repair needed. 4 45
generate a dynamic mysql query 2 41
Closing database connection after prepared statement 1 44
A lot of articles have been written on splitting mysqldump and grabbing the required tables. A long while back, when Shlomi ( had suggested a “sed” way, I actually shell …
Introduction In this installment of my SQL tidbits, I will be looking at parsing Extensible Markup Language (XML) directly passed as string parameters to MySQL 5.1.5 or higher. These would be instances where LOAD_FILE (…
I designed this idea while studying technology in the classroom.  This is a semester long project.  Students are asked to take photographs on a specific topic which they find meaningful, it can be a place or situation such as travel or homelessness.…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

914 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now