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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T18:48:40+00:00 2026-06-17T18:48:40+00:00

I need help with DISTINCT . I would like to display Distinct row but

  • 0

I need help with DISTINCT. I would like to display Distinct row but display also all rows

Example this table from database:

+----+-----+-----+
|col1|col2 |col3 |
+----+-----+-----+
|A   |one  |two  |
|A   |three|four |
|A   |five |six  |
|B   |seven|eight|
|B   |nine |ten  |
+----+-----+-----+

I would like the display to look like this :

A
one  |two
three|four
five |six

B
seven|eight
nine |ten

Can anyone help?

  • 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-17T18:48:42+00:00Added an answer on June 17, 2026 at 6:48 pm

    The easiest way would be to fetch all rows from the database, and then group them in PHP.

    // Querying:
    $query = mysql_query('select * from tbl');
    $results = array(); // Store all results in an array, grouped by col1
    
    while($row = mysql_fetch_assoc($query)) {
        $col1 = $row['col1'];
    
        // This is basically grouping your rows by col1
        if(!isset($results[$col1]))
            $results[$col1] = array();
        $results[$col1][] = $row;
    }
    
    // Displaying:
    foreach($results as $col1 => $rows) {
        echo "<h1>" . $col1 . "</h1>";
    
        foreach($rows as $row) {
            echo $row['col2'] . "|" . $row['col3'] . "<br />";
        }
    }
    

    Yields:

    <h1>A</h1>
    one  |two
    three|four
    five |six
    
    <h1>B</h1>
    seven|eight
    nine |ten
    

    Note that I use the deprecated mysql_functions just for simplicity, do not use them in production.

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

Sidebar

Related Questions

Need help writing a script downloads data from google insight using c# this is
need help in error in database pivot. i have table tamed table_score like below:
I need some help in SQL Server I have a number of table rows
I need to write a hibernate criteria for this SQL: select distinct USER_ID from
need help/guide for sql select query, I have 2 table stock and stock_history, in
I need help with one ajax function This is raw page setup. Page will
I would love some help on a particular design. This is the code I
I would like some help in setting up a project in SVN with regards
Arrrgh, I am not getting this. I have a table of accounts from Dynamics
I'm struggling with a query where I need to SUM DISTINCT Rows. There has

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.