How to select multiple rows of mysql table as a single row

Nathan

I have member table like below

MemberID    Name     BookID
    1       ABC         10
    1       ABC         14
    2       XYZ         10
    3       PQR         14

I want to select a MemberID that contains both the BOOKID 10 and 14 in single row.

Expected Output:

MemberID
1

I have tried below code but it doesnt work:

select MemberID from member where BookID IN (10,14)
Beginner

You can try like this:

SELECT MemberID, GROUP_CONCAT(BookID) AS BookID
FROM member
GROUP BY MemberID
HAVING FIND_IN_SET(10, BookID) > 0 AND FIND_IN_SET(14, BookID) > 0

Here is the SQLFIDDLE.

Another solution can be using JOIN like this:

SELECT x.MemberID
FROM member x
INNER JOIN member y ON x.MemberID = y.MemberID
  AND x.BookID = 10
  AND y.BookID = 14

Here is the SQLFIDDLE.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to select a single row where multiple rows exist from a table

From Dev

How to select a single row where multiple rows exist from a table

From Dev

MySQL query - single row in one table with multiple rows in another table

From Dev

MYSQL combine multiple rows into single row using join with another table

From Dev

how to select one row from one table and multiple rows from other table using joins in mysql,

From Dev

How to get multiple rows from single row of table?

From Dev

How to create multiple rows from single row with time interval in MySQL

From Dev

How to convert multiple rows(but one column) into a single row in MySQL

From Dev

select single row from multiple rows by id

From Dev

How to insert a single row in the parent table and then multiple rows in the child table in single SQL in PostgreSQL?

From Dev

How to insert a single row in the parent table and then multiple rows in the child table in single SQL in PostgreSQL?

From Dev

Combining data from multiple MySql tables, in multiple rows, into a single row for a SELECT statement

From Dev

how to select a single row in mysql?

From Dev

Inserting multiple rows into a single row mysql

From Dev

MySql get multiple rows in single row

From Dev

MYSQL - Selecting multiple rows in a single row

From Dev

How to select two rows into a single row output

From Dev

How can you align multiple table rows against a single table row?

From Dev

How can you align multiple table rows against a single table row?

From Dev

How to display one row when table has multiple rows related to Single record in other table?

From Dev

How to combine multiple rows into a single row with pandas

From Dev

How to split a single row into multiple rows in SQL

From Dev

how combine multiple rows into a single row in Oracle?

From Dev

How to select data from several rows in a single table in one result row?

From Dev

Select multiple row values into single row with multi-table clauses

From Dev

How to select single row with max count using group by when multiple rows with same count exist

From Dev

How to select single row with max count using group by when multiple rows with same count exist

From Dev

How to select a single row multiple times in PostgreSql

From Dev

How do I split a single row into multiple rows and Insert into a table in Oracle?

Related Related

  1. 1

    How to select a single row where multiple rows exist from a table

  2. 2

    How to select a single row where multiple rows exist from a table

  3. 3

    MySQL query - single row in one table with multiple rows in another table

  4. 4

    MYSQL combine multiple rows into single row using join with another table

  5. 5

    how to select one row from one table and multiple rows from other table using joins in mysql,

  6. 6

    How to get multiple rows from single row of table?

  7. 7

    How to create multiple rows from single row with time interval in MySQL

  8. 8

    How to convert multiple rows(but one column) into a single row in MySQL

  9. 9

    select single row from multiple rows by id

  10. 10

    How to insert a single row in the parent table and then multiple rows in the child table in single SQL in PostgreSQL?

  11. 11

    How to insert a single row in the parent table and then multiple rows in the child table in single SQL in PostgreSQL?

  12. 12

    Combining data from multiple MySql tables, in multiple rows, into a single row for a SELECT statement

  13. 13

    how to select a single row in mysql?

  14. 14

    Inserting multiple rows into a single row mysql

  15. 15

    MySql get multiple rows in single row

  16. 16

    MYSQL - Selecting multiple rows in a single row

  17. 17

    How to select two rows into a single row output

  18. 18

    How can you align multiple table rows against a single table row?

  19. 19

    How can you align multiple table rows against a single table row?

  20. 20

    How to display one row when table has multiple rows related to Single record in other table?

  21. 21

    How to combine multiple rows into a single row with pandas

  22. 22

    How to split a single row into multiple rows in SQL

  23. 23

    how combine multiple rows into a single row in Oracle?

  24. 24

    How to select data from several rows in a single table in one result row?

  25. 25

    Select multiple row values into single row with multi-table clauses

  26. 26

    How to select single row with max count using group by when multiple rows with same count exist

  27. 27

    How to select single row with max count using group by when multiple rows with same count exist

  28. 28

    How to select a single row multiple times in PostgreSql

  29. 29

    How do I split a single row into multiple rows and Insert into a table in Oracle?

HotTag

Archive