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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T08:44:55+00:00 2026-05-12T08:44:55+00:00

My question is very similar to this one How to reference a custom field

  • 0

My question is very similar to this one How to reference a custom field in SQL I have the following query:

SELECT * , (SELECT COUNT( id ) 
FROM cms_store_items
WHERE speaker = cms_store_items_speakers.id
) AS count
FROM cms_store_items_speakers
LIMIT 0 , 30

I need to add a WHERE clause that looks like WHERE count > 0 but when I do I get the error Unknown column 'count' in 'where clause' is there anyway for me to reference the custom field in my where clause without duplicating logic?

I could just place the logic for the where clause in my code but I don’t want to send what may well be more then 1000 rows to the app if not needed, it just seems like a waste of resources.

  • 1 1 Answer
  • 1 View
  • 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-12T08:44:55+00:00Added an answer on May 12, 2026 at 8:44 am

    Well, to do this strictly the way you’re doing it:

    select
    *
    from
    (
        SELECT * , (SELECT COUNT( id ) 
        FROM cms_store_items
        WHERE speaker = cms_store_items_speakers.id
        ) AS count
        FROM cms_store_items_speakers
    ) a
    where a.count > 0
    LIMIT 0 , 30
    

    It would probably be better to do the following, though. It makes good use of the having clause:

    select
        s.id,
        s.col1,
        count(i.speaker) as count
    from
        cms_store_items_speakers s
        left join cms_store_items i on
            s.id = i.speaker
    group by
        s.id,
        s.col1
    having
        count(i.speaker) > 0
    limit 0, 30
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an error very similar to the one addressed in this question .
I have a question that is very similar to this one: Setting focus to
My question is very similar to this one, and I would have followed up
My question popped up a very similar question, this one . But the accepted
I know that this is a repeated question. I have found very similar questions
My current problem is very similar to this one . I have a downloadFile(URL)
I'm asking a question very similar to this one —dare I say identical? An
My question is very similar to this one . The application I'm developing is
this oughta be an easy one. My question is very similar to this one
Firstly, I realise that this is a very similar question to this one: Which

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.