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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T07:01:11+00:00 2026-05-30T07:01:11+00:00

I am having a problem with trying to count a number of rows and

  • 0

I am having a problem with trying to count a number of rows and then grouping them in SQL.

I have used the SELECT query below to create a table.

SELECT ward.ward_no, bed_no   
FROM ward, bed 
WHERE ward.ward_no = bed.ward_no

.

ward_no     bed_no

w1         1.
w1         2.
w1         3.    
w1         4.    
w2         5.    
w2         6.    
w2         7.   
w3         8.    
w3         9.    
w3         10.   
w4         11.

What I am trying to do is create a table where it shows each ward no ie w1 and a field showing how many fields is in it.

eg.

w1   3.
w2   3.
w3   3

I have tried the COUNT & GROUP BY fields like so…

SELECT ward.ward_no, bed_no
FROM ward, bed  
WHERE ward.ward_no = bed.ward_no  
AND COUNT (bed_no) AS beds_in_ward  
GROUP BY ward_no;

but with no joy, any advice would be fully appreciated

  • 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-30T07:01:13+00:00Added an answer on May 30, 2026 at 7:01 am

    You have your COUNT() in the wrong place

    SELECT ward.ward_no, COUNT (bed_no) AS beds_in_ward
    FROM ward
    INNER JOIN bed
    ON ward.ward_no = bed.ward_no
    GROUP BY ward_no;
    

    I also updated the query to use JOIN instead of the ',' between your tables.

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

Sidebar

Related Questions

I'm having a problem using the java.text.MessageFormat object. I'm trying to create SQL insert
I'm trying to count the number of rows of my table that meet specific
Having a problem with the following Query. i have a device table which logs
I'm having a little problem with the .length() property. I'm trying to count the
Evening folks, I have a complex MySQL COUNT query I am trying to perform
Having a problem trying to create a function, as part of a BizTalk helper
I am having a problem trying to use the prependTo() function in jQuery... for
I'm having a problem trying to format the output on the jQuery UI datepicker.
I'm having a problem when trying to pass an array back to a COM
I am having problem that when i am trying to submit the form by

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.