1

I have this following table

    id |         title
-------+--------------------
    16 | Little Women
    16 | The Tell-Tale Heart
    16 | Practical PostgreSQL
    16 | Dynamic Anatomy
    18 | The Cat in the Hat
    18 | Dune
    20 | A Space Odyssey
    20 | Goodnight Moon
    41 | The Shining
    41 | Programming Python
    41 | Perl Cookbook

I want the output should come like this shown below:

    id |         title
-------+------------------
    16 | Little Women
       | The Tell-Tale Heart
       | Practical PostgreSQL
       | Dynamic Anatomy
    18 | The Cat in the Hat
       | Dune
    20 | A Space Odyssey
       | Goodnight Moon
    41 | The Shining
       | Programming Python
       | Perl Cookbook

Displaying all records that is related with id in the right column using mysql. How can I do this? Please provide me the solution for this I will be very grateful.

Raging Bull
  • 18,593
  • 13
  • 50
  • 55
Amuk Saxena
  • 1,521
  • 4
  • 18
  • 44

3 Answers3

1

Try this

SELECT id,GROUP_CONCAT(title separator '\n') FROM mytable GROUP BY id
Sadikhasan
  • 18,365
  • 21
  • 80
  • 122
0

This should be done in your presentation layer e.g. your form, report, webpage, etc.

SELECT id
     , title
FROM   your_table
ORDER
    BY id
     , title

Your presentation code can then decide whether to display the ID each time.

gvee
  • 16,732
  • 35
  • 50
-1

try this, you will get the results with comma separated.

SELECT id,GROUP_CONCAT(title) FROM mytable GROUP BY id
ravikumar
  • 893
  • 1
  • 8
  • 12