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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T09:37:18+00:00 2026-05-25T09:37:18+00:00

Here is the SQL Statement that I am using.. $sql = SELECT surname, forename,

  • 0

Here is the SQL Statement that I am using..

$sql = "SELECT surname, forename, count(*) FROM people WHERE user_id='$user_id'
        GROUP BY surname ORDER BY time";

$result = mysql_query($sql);
$count=mysql_num_rows($result);

if($count > 0){
while($row = mysql_fetch_array($result)) {
$i = $i +1;
$person[$i] = $row['surname'].'&&'.$row['forename'];
} 

What I would like to get is all the entries from the people database relative to user_id grouped by surname and ordered by the time that they were entered in to the database. e.g.

12:00  Smith  James
13:00  Smith  Linda
14:00  Smith  Sam

12:30  OtherSurname  Lydia
13:30  OtherSurname  Harry
14:30  OtherSurname  Phil

The problem at the moment is that I only get one result for each surname.
How can I use the SELECT statement with GROUP BY and ORDER BY to get all of the entries? thank you.

  • 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-25T09:37:19+00:00Added an answer on May 25, 2026 at 9:37 am

    Change your GROUP BY to:

    GROUP BY surname, forename
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here's my current SQL statement: SEARCH_ALBUMS_SQL = SELECT * FROM albums WHERE title LIKE
Here is my SQL Statement which is not returning DISTINCT Thread Titles. SELECT DISTINCT
I read about using the CASE expression inside the WHERE clause here: http://scottelkin.com/sql/using-a-case-statement-in-a-sql-where-clause/ I'm
I have a problem with a SQL statement: Using this select a.id as ID,
Bit of a complicated SQL question here. I currently have a SELECT statement which
Have other people here played with SQL Server 2008 Compression at either the page
I'm using Microsoft SQL Server 2005. I'm creating a random record generator that will
I am making a simple select from mySQL using PHP. I am doing something
I need to select data from two table using a join. This is fairly
I am using MS SQL Server 2005 (9.0.4035) and trying to find rows that

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.