Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2013-12-14
2
Medium Priority
?
365 Views
Last Modified: 2013-12-14
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
Comment
Question by:rgb192
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 32

Accepted Solution

by:
Daniel Wilson earned 2000 total points
ID: 39718824
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
 

Author Closing Comment

by:rgb192
ID: 39718971
Yes this corrects the syntax error.

Thanks
0

Featured Post

What’s Wrong with Your Cloud Strategy ?

Even as many CIOs are embracing a cloud-first strategy, the reality is that moving to the cloud is a lengthy process and the end-state is likely to be a blend of multiple clouds—public and private. Learn why multicloud solutions matter in this webinar by Nimble Storage.

Question has a verified solution.

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

This post looks at MongoDB and MySQL, and covers high-level MongoDB strengths, weaknesses, features, and uses from the perspective of an SQL user.
In this blog post, we’ll look at how ClickHouse performs in a general analytical workload using the star schema benchmark test.
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…

636 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