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

  • Home
  • SEARCH
  • 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 526855
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T08:49:15+00:00 2026-05-13T08:49:15+00:00

Ok. This version of select works: $select = $this->select(); $select->setIntegrityCheck(false); $select->from(array(‘u’ => $this->_name), array(‘u.id’,

  • 0

Ok. This version of select works:

    $select = $this->select();
    $select->setIntegrityCheck(false);
    $select->from(array('u' => $this->_name),
                  array('u.id', 'u.username', 'u.avatar_path',
                        '(SELECT COUNT(*) FROM media WHERE user_id = u.id) media_count'));
    $where = "u.status = 'active' AND u.avatar_path <> 'images/photo-thumb.gif' AND u.show_on_homepage = 1";
    $where .= " AND (u.status_message IS NOT NULL OR u.profile_theme_id IS NOT NULL)";
    $select->where($where);
    return $this->fetchAll($select);

Now what I did was I just added a single condition on the 7th line (media_count > 0) so it looks like this:

    $select = $this->select();
    $select->setIntegrityCheck(false);
    $select->from(array('u' => $this->_name),
                  array('u.id', 'u.username', 'u.avatar_path',
                        '(SELECT COUNT(*) FROM media WHERE user_id = u.id) media_count'));
    $where = "u.status = 'active' AND u.avatar_path <> 'images/photo-thumb.gif' AND u.show_on_homepage = 1";
    $where .= " AND (u.status_message IS NOT NULL OR u.profile_theme_id IS NOT NULL OR media_count > 0)";
    $select->where($where);
    return $this->fetchAll($select);

And this already doesn’t work and I get an error:

SQLSTATE[42S22]: Column not found: 1054 Unknown column 'm.media_count' in 'where clause'

When I remove the condition it works. I also tried using u.media_count without success.

EDIT: The media_count value works. I have left out the condition (media_count > 0) and then I did var_dump on the result set and the key media_count is in the array with correct value.

EDIT2: I have simplified the selects above (I have removed unimportant lines).

  • 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-13T08:49:15+00:00Added an answer on May 13, 2026 at 8:49 am

    I’m not specifically familiar with the zend-framework, but I think the problem is that media_count is not an actual column of the table. Try replacing

    media_count > 0
    

    with

    (SELECT COUNT(*) FROM media WHERE user_id = u.id) > 0
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Follow up to this question This (similar version from old link) works in SQL
This is a simpler version of the query I have. Alias1 as (select distinct
Currently, I have this version of the autocomplete control working when returning XML from
Here's the test page I'm using. This version works fine, forwarding to #success: <!DOCTYPE
I'm trying to benchmark a stored procedure. select benchmark(100000000,(select 1)); this benchmark works but
i have created this query that works OK: $q1 = Doctrine_Query::create() ->from('Usuario u') ->leftJoin('u.AmigoUsuario
Recently I have done this part of code. It does work, but select() works
I've a this query in mySQL (MyISAM): SELECT * FROM `links` WHERE `id` IN
Short Version This query works in the database but fails with Linq To NHibernate.
i was trying to run this query: ( (SELECT * FROM (SELECT * FROM

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.