"GROUP_CONCAT()" Multiple columns through foreign key

L.kifa

I have the following tables

Book table

id     title       authors
3      Linux  

authors table

id   firstname  lastname   fk
1      name       name     3
2      name2      name     3

I would like to query authors table to get authors column filled something like this table using GROUP_CONCAT()

id   title            authors
3    Linux    name name | name2 name2
CL.

For a single book whose ID you know, you can get the list of authors as a single value like this:

SELECT group_concat(firstname || ' ' || lastname)
FROM authors
WHERE fk = ?;

Just use this as a correlated subquery in the actual query:

SELECT id,
       title,
       (SELECT group_concat(firstname || ' ' || lastname, ' | ')
        FROM authors
        WHERE fk = book.id
       ) AS authors
FROM book;

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Java

GROUP_CONCAT numbering with multiple columns group by

From Dev

mysql GROUP_CONCAT DISTINCT multiple columns

From Dev

GROUP_CONCAT on two columns

From Dev

Mysql group_concat of repeated keys and count of repetition of multiple columns in 1 query ( Query Optimization )

From Dev

Searching through the GROUP_CONCAT values in MYSQLI?

From Dev

Group_Concat multple columns in sql

From Dev

SQL GROUP_CONCAT split in different columns

From Dev

Group_concat with columns of a particular type in the first

From Dev

how to group_concat two columns

From Dev

mysql multiple group_concat order preservation

From Dev

MySQL Use GROUP_CONCAT with Multiple JOINS

From Dev

GROUP_CONCAT multiple fields with a different separator

From Dev

group_concat with multiple joins in MySQL

From Dev

How to convert rows into columns without GROUP_CONCAT?

From Dev

MySQL - GROUP_CONCAT() on names of temporary table columns?

From Dev

Group_concat, joining a column into a row, if other columns are equal

From Dev

how to use GROUP_CONCAT of two columns with query

From Dev

MySQL - GROUP_CONCAT with two columns from different tables

From Dev

How to convert rows into columns without GROUP_CONCAT?

From Dev

SQL Query, Group_Concat of multiple left joins and nested queries

From Dev

Codeigniter Multiple Join Not Getting Sub Cat "Name" with Group_Concat

From Dev

GROUP_CONCAT with FIND_IN_SET, multiple joins

From Dev

Sum of data in multiple rows that echo with GROUP_CONCAT in CodeIgniter

From Dev

SQL Query, Group_Concat of multiple left joins and nested queries

From Dev

Mysql - optimisation - multiple group_concat & joins using having

From Dev

Merge Multiple Rows Based On Unique Identifier in SQL Server (GROUP_CONCAT for SQL Server)?

From Dev

Foreign key for multiple tables and columns?

From Dev

GROUP_CONCAT with limit

From Dev

Sorting in group_concat

Related Related

  1. 1

    GROUP_CONCAT numbering with multiple columns group by

  2. 2

    mysql GROUP_CONCAT DISTINCT multiple columns

  3. 3

    GROUP_CONCAT on two columns

  4. 4

    Mysql group_concat of repeated keys and count of repetition of multiple columns in 1 query ( Query Optimization )

  5. 5

    Searching through the GROUP_CONCAT values in MYSQLI?

  6. 6

    Group_Concat multple columns in sql

  7. 7

    SQL GROUP_CONCAT split in different columns

  8. 8

    Group_concat with columns of a particular type in the first

  9. 9

    how to group_concat two columns

  10. 10

    mysql multiple group_concat order preservation

  11. 11

    MySQL Use GROUP_CONCAT with Multiple JOINS

  12. 12

    GROUP_CONCAT multiple fields with a different separator

  13. 13

    group_concat with multiple joins in MySQL

  14. 14

    How to convert rows into columns without GROUP_CONCAT?

  15. 15

    MySQL - GROUP_CONCAT() on names of temporary table columns?

  16. 16

    Group_concat, joining a column into a row, if other columns are equal

  17. 17

    how to use GROUP_CONCAT of two columns with query

  18. 18

    MySQL - GROUP_CONCAT with two columns from different tables

  19. 19

    How to convert rows into columns without GROUP_CONCAT?

  20. 20

    SQL Query, Group_Concat of multiple left joins and nested queries

  21. 21

    Codeigniter Multiple Join Not Getting Sub Cat "Name" with Group_Concat

  22. 22

    GROUP_CONCAT with FIND_IN_SET, multiple joins

  23. 23

    Sum of data in multiple rows that echo with GROUP_CONCAT in CodeIgniter

  24. 24

    SQL Query, Group_Concat of multiple left joins and nested queries

  25. 25

    Mysql - optimisation - multiple group_concat & joins using having

  26. 26

    Merge Multiple Rows Based On Unique Identifier in SQL Server (GROUP_CONCAT for SQL Server)?

  27. 27

    Foreign key for multiple tables and columns?

  28. 28

    GROUP_CONCAT with limit

  29. 29

    Sorting in group_concat

HotTag

Archive