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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T07:05:46+00:00 2026-06-03T07:05:46+00:00

Table: laterecords ———– studentid – varchar latetime – datetime reason – varchar My Query:

  • 0

Table:

laterecords
-----------
studentid - varchar
latetime - datetime
reason - varchar

My Query:

SELECT laterecords.studentid,
laterecords.latetime,
laterecords.reason,
( SELECT Count(laterecords.studentid) FROM laterecords 
      GROUP BY laterecords.studentid ) AS late_count 
FROM laterecords

I’m getting ” MySQL Subquery Returns more than one row” error.

I know a workaround for this query to use the following query:

SELECT laterecords.studentid,
laterecords.latetime,
laterecords.reason 
FROM laterecords

Then using php loop to though the results and do below query to get the late_count and echo it out:

SELECT Count(laterecords.studentid) AS late_count FROM laterecords 

But i think there might be a better solution ?

  • 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-06-03T07:05:47+00:00Added an answer on June 3, 2026 at 7:05 am

    The simple fix is to add a WHERE clause in your subquery:

    SELECT
        studentid,
        latetime,
        reason,
        (SELECT COUNT(*)
         FROM laterecords AS B
         WHERE A.studentid = B.student.id) AS late_count 
    FROM laterecords AS A
    

    A better option (in terms of performance) is to use a join:

    SELECT
        A.studentid,
        A.latetime,
        A.reason,
        B.total
    FROM laterecords AS A
    JOIN 
    (
        SELECT studentid, COUNT(*) AS total
        FROM laterecords 
        GROUP BY studentid
    ) AS B
    ON A.studentid = B.studentid
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Table: laterecords ----------- studentid - varchar latetime - datetime reason - varchar students --------
Table#Appointments: ID, Name, LocationID, Created Currently I have: SELECT * FROM Appointments WHERE Created
Table structure: title { name varchar(100) } If I try to insert a following
Table in question (striped unneeded cols): car_id INT(11) PK url VARCHAR(100) signup TIMESTAMP Default
Table Schema Table Name: file_manager_folder Rows: id , parentId , name My query simulates
Table (ipvote) Table (pictures) What is the SQL query to retrieve all the images
Table - user_feed column name - date_n_time (type - datetime) How do I write
Table: CREATE TABLE Instrument ( Id INT IDENTITY , Name VARCHAR(50) , Tenor VARCHAR(10)
Table view cell management has driving me crazy from past two days. Please check
table is CREATE TABLE `news` ( `id` bigint(20) NOT NULL auto_increment, `title` varchar(255) default

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.