mysql join one to many relationship and print in different rows

fuschia

I have a table for example citations that contains:

paperkey 
1
2

and another table source that contains

paperkey | authors
1          a
1          b
1          c
2          d
2          e
3          x
5          y 
6          z
6          a

The paperkey in table citation is the subset of paperkey in source table. So I need to take the authors of paperkey in table citation. My expected output is:

1          a
1          b
1          c
2          d
2          e

I tried but I could not find the relevant query. Currently I have the query:

select a.paperkey, groupconcat(b.authors)
from citations a
left join source b
on a.paperkey = b.paperkey
group by a.paperkey;

but the result is

1         a,b,c
2         d,e

This is the best I could do. But I needed to produce the output I expected so that the authors are printed in different rows and I could not find any query that works like that.

Get Off My Lawn

You shouldn't have to have the need to group the results, you should just need to order the results like this:

select a.paperkey, b.authors
from citations a
left join source b using(paperkey)
order by b.paperkey, b.authors;

I personally would us using, since the column names are the same.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Mysql one to many join, rows to columns

From Dev

Sqlalchemy one to many relationship join?

From Dev

Many to one relationship, unwanted JOIN

From Dev

mySQL JOIN on one to many

From Dev

MySQL, join many to many relationship query

From Dev

Hibernate Criteria fetchType JOIN with one-to-many relationship shows different behavior with and without aliases

From Dev

Mysql Left Join (1 to many relationship)

From Dev

Mysql join with one to many relations

From Dev

Hibernate one to many relationship with join table with addition columns in join table

From Dev

Get rows with only one reference in many-to-many relationship

From Dev

Combine multiple rows to one (many-many relationship)

From Dev

MySQL one to many relationship, with shared values

From Dev

create mysql table with one to many relationship

From Dev

MySQL One to Many relationship exlusions based on criteria

From Dev

MySQL - multiple values in one field or many-to-many relationship?

From Dev

SQL join one to many relationship - count number of votes per image?

From Dev

Oracle SQL Developer - JOIN on 2 queries with a one-to-many relationship

From Dev

Linq to Sql One to many relationship string.join

From Dev

result repetition in SQL inner join with one to many relationship

From Dev

How to join a one-to-many relationship in Entity Framework?

From Dev

SQL Query with Aggregate function on Left Join of One-to-Many Relationship

From Dev

Many to many relationship and MySQL

From Dev

Mysql Many to Many relationship

From Dev

In one to many relationship, return distinct rows based on MIN value

From Dev

One-to-Many NSFetchedResultsController with as much rows as the relationship NSSet contains

From Dev

MySQL: join many tables on one Statement

From Dev

mysql join one to many last record

From Dev

MySQL: join many tables on one Statement

From Dev

Select values from different rows in a mysql join

Related Related

  1. 1

    Mysql one to many join, rows to columns

  2. 2

    Sqlalchemy one to many relationship join?

  3. 3

    Many to one relationship, unwanted JOIN

  4. 4

    mySQL JOIN on one to many

  5. 5

    MySQL, join many to many relationship query

  6. 6

    Hibernate Criteria fetchType JOIN with one-to-many relationship shows different behavior with and without aliases

  7. 7

    Mysql Left Join (1 to many relationship)

  8. 8

    Mysql join with one to many relations

  9. 9

    Hibernate one to many relationship with join table with addition columns in join table

  10. 10

    Get rows with only one reference in many-to-many relationship

  11. 11

    Combine multiple rows to one (many-many relationship)

  12. 12

    MySQL one to many relationship, with shared values

  13. 13

    create mysql table with one to many relationship

  14. 14

    MySQL One to Many relationship exlusions based on criteria

  15. 15

    MySQL - multiple values in one field or many-to-many relationship?

  16. 16

    SQL join one to many relationship - count number of votes per image?

  17. 17

    Oracle SQL Developer - JOIN on 2 queries with a one-to-many relationship

  18. 18

    Linq to Sql One to many relationship string.join

  19. 19

    result repetition in SQL inner join with one to many relationship

  20. 20

    How to join a one-to-many relationship in Entity Framework?

  21. 21

    SQL Query with Aggregate function on Left Join of One-to-Many Relationship

  22. 22

    Many to many relationship and MySQL

  23. 23

    Mysql Many to Many relationship

  24. 24

    In one to many relationship, return distinct rows based on MIN value

  25. 25

    One-to-Many NSFetchedResultsController with as much rows as the relationship NSSet contains

  26. 26

    MySQL: join many tables on one Statement

  27. 27

    mysql join one to many last record

  28. 28

    MySQL: join many tables on one Statement

  29. 29

    Select values from different rows in a mysql join

HotTag

Archive