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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T10:10:18+00:00 2026-05-20T10:10:18+00:00

Firstly, I’ve read through the posts with matching names, and I’ve tried integrating some

  • 0

Firstly, I’ve read through the posts with matching names, and I’ve tried integrating some of the solutions but I cant seem to get this SQL Query to work…

The problem seems to revolve around the COUNT function on line 8.

Here it is..


SELECT `purchase_orders`.`purchase_order_id`,`purchase_orders`.`sequence_id`,`purchase_orders`.`order_number`,`vendors`.`name`,`purchase_orders`.`date`,COUNT(`purchase_order_items`.`purchase_order_id`) `item_count`,`purchase_orders`.`total_value`,`purchase_orders`.`status`,`users`.`first`
FROM (`purchase_orders`, `vendors`, `purchase_order_items`,`users`) 
WHERE `purchase_orders`.`aid`='c4ca4238a0b923820dcc509a6f75849b'AND`purchase_orders`.`vendor_id`=`vendors`.`vid`AND`purchase_orders`.`created_by`=`users`.`uid`AND`purchase_order_items`.`purchase_order_id`=`purchase_orders`.`purchase_order_id` AND `purchase_orders`.`purchase_order_id` LIKE '%122%' 
OR `purchase_orders`.`aid`='c4ca4238a0b923820dcc509a6f75849b'AND`purchase_orders`.`vendor_id`=`vendors`.`vid`AND`purchase_orders`.`created_by`=`users`.`uid`AND`purchase_order_items`.`purchase_order_id`=`purchase_orders`.`purchase_order_id` AND `purchase_orders`.`sequence_id` LIKE '%122%' 
OR `purchase_orders`.`aid`='c4ca4238a0b923820dcc509a6f75849b'AND`purchase_orders`.`vendor_id`=`vendors`.`vid`AND`purchase_orders`.`created_by`=`users`.`uid`AND`purchase_order_items`.`purchase_order_id`=`purchase_orders`.`purchase_order_id` AND `purchase_orders`.`order_number` LIKE '%122%' 
OR `purchase_orders`.`aid`='c4ca4238a0b923820dcc509a6f75849b'AND`purchase_orders`.`vendor_id`=`vendors`.`vid`AND`purchase_orders`.`created_by`=`users`.`uid`AND`purchase_order_items`.`purchase_order_id`=`purchase_orders`.`purchase_order_id` AND `vendors`.`name` LIKE '%122%' 
OR `purchase_orders`.`aid`='c4ca4238a0b923820dcc509a6f75849b'AND`purchase_orders`.`vendor_id`=`vendors`.`vid`AND`purchase_orders`.`created_by`=`users`.`uid`AND`purchase_order_items`.`purchase_order_id`=`purchase_orders`.`purchase_order_id` AND `purchase_orders`.`date` LIKE '%122%' 
OR `purchase_orders`.`aid`='c4ca4238a0b923820dcc509a6f75849b'AND`purchase_orders`.`vendor_id`=`vendors`.`vid`AND`purchase_orders`.`created_by`=`users`.`uid`AND`purchase_order_items`.`purchase_order_id`=`purchase_orders`.`purchase_order_id` AND COUNT(`purchase_order_items`.`purchase_order_id`) LIKE '%122%'
OR `purchase_orders`.`aid`='c4ca4238a0b923820dcc509a6f75849b'AND`purchase_orders`.`vendor_id`=`vendors`.`vid`AND`purchase_orders`.`created_by`=`users`.`uid`AND`purchase_order_items`.`purchase_order_id`=`purchase_orders`.`purchase_order_id` AND `purchase_orders`.`total_value` LIKE '%122%' 
OR `purchase_orders`.`aid`='c4ca4238a0b923820dcc509a6f75849b'AND`purchase_orders`.`vendor_id`=`vendors`.`vid`AND`purchase_orders`.`created_by`=`users`.`uid`AND`purchase_order_items`.`purchase_order_id`=`purchase_orders`.`purchase_order_id` AND `purchase_orders`.`status` LIKE '%122%' 
OR `purchase_orders`.`aid`='c4ca4238a0b923820dcc509a6f75849b'AND`purchase_orders`.`vendor_id`=`vendors`.`vid`AND`purchase_orders`.`created_by`=`users`.`uid`AND`purchase_order_items`.`purchase_order_id`=`purchase_orders`.`purchase_order_id` AND `users`.`first` LIKE '%122%'  
GROUP BY `purchase_orders`.`purchase_order_id`
ORDER BY `purchase_orders`.`purchase_order_id` ASC 
LIMIT 0,1
  • 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-20T10:10:19+00:00Added an answer on May 20, 2026 at 10:10 am

    When you use COUNT(xxx) in a SQL, you need to use it in the HAVING clause:

    e.g.

    HAVING COUNT(xxx) > yyyy
    

    Also, generally you want to GROUP BY the fields that you don’t use aggregate functions on. For example:

    SELECT person_name
         , SUM(bonuses)
      FROM person x
         , person_bonus y
     WHERE x.person_id = y.person_id
    

    GROUP BY person_name

    As I add additional columns to that SELECT statement, I need to either use another aggregate function (COUNT, SUM, etc.) on them, or I need to GROUP BY them.

    And again, anything you are using an aggregate function on can be used in your HAVING clause:

        SELECT person_name
             , SUM(bonuses)
          FROM person x
             , person_bonus y
         WHERE x.person_id = y.person_id
       GROUP BY person_name
         HAVING SUM(bonuses) > 50000  // I wish :)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Firstly I've looked at a lot of posts on Stackoverflow but I don't see
Firstly, I was wondering if there was some kind of built in function that
Firstly I know that there are many question and solutions to correct thread marshalling
Firstly, I'm not using rails. This is vanilla ruby application. I've read about packaging
Firstly, apologies for all the XAML. I've tried for a few days to resolve
Firstly, I have search Stack Overflow for the answer, but I have not found
Firstly anyone else trying to get onto forum.hibernate.org. I have been trying for a
Firstly, appologies if i get any terminology wrong on the upcoming post, this is
Firstly I just want to say I'm not an ASP developer, I'm PHP through
Firstly, there have some tag links in my main page. click each one, post

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.