Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8839083
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T10:09:38+00:00 2026-06-14T10:09:38+00:00

I need to set a value to 1 in table where the count for

  • 0

I need to set a value to 1 in table where the count for a given role in another table is > 1.

The table cursillo.members has fields memid and hsd. Table cursillo.teams has fields memid (the link between the two) a field called movement and another called role.

What I am trying to accomplish is something similar to this:

update cursillo.members_eligible p, cursillo.teams pp
   set p.hsd=1     
 where p.memid = pp.memid AND (pp.role = 'HSD' OR pp.role = 'SD')
   and pp.movement = 'Cursillo' AND count(pp.role) > 1;

or this:

update members_eligibile
   set hsd=1 
  from teams 
 where teams.memid=members_eligible.memid 
   and (teams.role = 'HSD' OR teams.role = 'SD')  
   and teams.movement = 'Cursillo' 
   and count(teams.role) > 1;

In other words if a given memid has more than one record in the cursillo.teams table where the value of the role is equal to either HSD or SD, then set cursillo.members_eligible.hsd to 1.

I can’t figure out to handle the count() part.

Thanks,
Mike Reed

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T10:09:39+00:00Added an answer on June 14, 2026 at 10:09 am

    Possible duplicate question:

    MySQL – Using COUNT(*) in the WHERE clause

    Try using the ‘having’ keyword

    Here’s the relevant section from the linked answer (in this case, a select statement):

    select gid
    from `gd`
    group by gid 
    having count(*) > 10
    order by lastupdated desc
    

    It looks like ‘having’ can only be used in select statments though:
    http://www.mysqltutorial.org/mysql-having.aspx

    So you may need to have your update’s where clause include a select statement:

    update members_eligibile
       set hsd=1 
      from teams 
     where teams.memid=members_eligible.memid 
       and (teams.role = 'HSD' OR teams.role = 'SD')  
       and teams.movement = 'Cursillo' 
       and members_eligible.memid IN
       (SELECT members_eligible.memid from members_eligible where teams.memid=members_eligible.memid  having count(teams.role) > 1);
    

    You will have to adjust the select statement, I haven’t tested it

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have a table named tags which has 3 cols: id, value, count which
I need to set the value of a field in a form via JavaScript.
I need to sometimes set the value of an int to null and sometimes
I need to write a generic procedure that set value for one column or
In the code below, I need to set Variable1 to an arbitrary value so
I have a timestamp value in my table and it's set to on update
Given a table of input data I would like to have a set o
what wrong with this Query ??? i need this Query. UPDATE user_preferences SET user_preferences_value
On the select event of the datepicker I need to add and set values
I need a data structure that holds unique values (like a set), but also

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.