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 574763
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T13:51:58+00:00 2026-05-13T13:51:58+00:00

So, I want to apply a WHERE condition to a field assigned by a

  • 0

So, I want to apply a WHERE condition to a field assigned by a COUNT() AS clause. My query currently looks like this:

SELECT new_tags.tag_id
       , new_tags.tag_name
       , new_tags.tag_description
       , COUNT(DISTINCT new_tags_entries.entry_id) AS entry_count 
FROM (new_tags) 
JOIN new_tags_entries ON new_tags_entries.tag_id = new_tags.tag_id 
WHERE `new_tags`.`tag_name` LIKE '%w' 
AND `entry_count` < '1' 
GROUP BY new_tags.tag_id ORDER BY tag_name ASC

The bit that’s failing is the entry_count in the WHERE clause – it doesn’t know what the entry_count column is. My table looks like this:

new_tags {
    tag_id INT
    tag_name VARCHAR
}

new_tags_entries {
    tag_id INT
    entry_id INT
}

I want to filter the results by the number of distinct entry_ids in new_tags_entries that pertain to the tag ID.

Make sense?

Thanks in advance.

  • 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-05-13T13:51:58+00:00Added an answer on May 13, 2026 at 1:51 pm

    To filter on aggegated values use the HAVING clause…

    SELECT  
       new_tags.tag_id, new_tags.tag_name,  
       new_tags.tag_description,  
       COUNT(DISTINCT new_tags_entries.entry_id) AS entry_count  
    FROM (new_tags)  
    JOIN new_tags_entries ON new_tags_entries.tag_id = new_tags.tag_id   
    WHERE `new_tags`.`tag_name` LIKE '%w'   
    GROUP BY new_tags.tag_id  
    HAVING COUNT(DISTINCT new_tags_entries.entry_id)  < '1' 
    ORDER BY tag_name ASC
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to apply a condition, after I passed another condition like this: List<Entity>
I want to apply a Storyboard to my Rectangle Fill like this: <Rectangle Name=MyRectangle
I want apply margin property for my html newsletter But Gmail ignores this CSS
I want to apply cycle to the div block with dynamic content. This content
I want to apply a rewrite condition, so that only *.php files are affected:
I have two activities but I want to apply a condition on application start,
I have a situation that I need to apply another Condition inside ON clause
I have a data.frame df like this: df <- data.frame (x=1:5,y=1:5) I want to
How to apply if condition in Switch statement, I want to calculate Average: however
So I want to apply a function over a matrix in R. This works

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.