How to return only one row from the right-most table using mysql join

Ewomazino Ukah

I have two tables. I want to join them in a way that only one record(the first matched record) in the right table is returned for the record in the left most table. the two tables have a one to many relationship. here are the tables below:

events table :

      -------------------------------------------------------------
      | event_id | event_name |event_details|event_venue|dress_code|
      -------------------------------------------------------------
      | 1        | club 92    |blah blahblah|somewhere  |something |
      | 2        | graduation |blah blahblah|somewhere  |something |
      | 3        | party      |blah blahblah|somewhere  |something |
      --------------------------------------------------------------

tickets table :

      -----------------------------------------------
      |ticket_id | ticket_name  | price | event_id  |
      -----------------------------------------------
      | 1        | first        |   0   |   1       |
      | 2        | second       |   10  |   1       |
      | 3        | third        |   100 |   1       |
      | 4        | fourth       |   10  |   2       |
      | 5        | fifth        |   200 |   2       |
      -----------------------------------------------

is this possible using join ? i'm open to any other ideas

Gordon Linoff

You can't do this just with a join. Here is one method:

select e.*, t.*
from events e join
     tickets t
     on e.event_id = t.event_id
where t.id = (select min(t2.id)
              from tickets t2
              where t2.event_id = t.event_id
             );

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Join two tables and return only one row from second table

From Dev

mysql return one row of right table

From Dev

MySQL join table return only one match

From Dev

How do I join the most recent row in one table to another table MYSQL

From Dev

MySQL: Return row count from second table using one query

From Dev

MySQL - How to select only two columns from a row in one table

From Dev

How do I join the most recent row in one table to most recent row in another table (oracle)

From Dev

MySQL LIKE from JOIN clause and GROUP_CONCAT returns only one row from joined table

From Dev

MySql LEFT JOIN returns only one NULL row from the other table

From Dev

How to return data from two tables only when the column value in one table is same as another table using MySQL?

From Dev

Mysql Query Join Table on the most recent row

From Dev

left join tables, use only one row from left table

From Dev

How to join row count of each group from right side 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 join only one row in joined table with postgres?

From Dev

How to use only one matching row of association table to join parents

From Dev

LEFT JOIN returns 1st row from left table only if right table is empty

From Dev

join one row from one mysql table to multiple row in second table

From Dev

MySQL JOIN - json returns data only from one table

From Dev

SQL One to many join - do not return rows from the 'one' table if ANY row in the 'many' table equals X

From Dev

MySQL LEFT JOIN is returning just one row with a where condition on the right table

From Dev

How to do this query in MySQL which one should I use using left join or right join or inner join?

From Dev

How to search a table using JS and return only the matching row?

From Dev

Mysql join table result as one row

From Dev

Trying to do a LEFT JOIN on two tables but want only one from the RIGHT TABLE

From Dev

MySQL returning only one row (most recent one)

From Dev

MySQL - if row is duplicate, return only the first one

From Dev

Adding entries from multiple MySQL tables using one single SQL join statement, but only if there are entries available in the second table

From Dev

Select MySQL results based on most current row in join table

Related Related

  1. 1

    Join two tables and return only one row from second table

  2. 2

    mysql return one row of right table

  3. 3

    MySQL join table return only one match

  4. 4

    How do I join the most recent row in one table to another table MYSQL

  5. 5

    MySQL: Return row count from second table using one query

  6. 6

    MySQL - How to select only two columns from a row in one table

  7. 7

    How do I join the most recent row in one table to most recent row in another table (oracle)

  8. 8

    MySQL LIKE from JOIN clause and GROUP_CONCAT returns only one row from joined table

  9. 9

    MySql LEFT JOIN returns only one NULL row from the other table

  10. 10

    How to return data from two tables only when the column value in one table is same as another table using MySQL?

  11. 11

    Mysql Query Join Table on the most recent row

  12. 12

    left join tables, use only one row from left table

  13. 13

    How to join row count of each group from right side table

  14. 14

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

  15. 15

    How to join only one row in joined table with postgres?

  16. 16

    How to use only one matching row of association table to join parents

  17. 17

    LEFT JOIN returns 1st row from left table only if right table is empty

  18. 18

    join one row from one mysql table to multiple row in second table

  19. 19

    MySQL JOIN - json returns data only from one table

  20. 20

    SQL One to many join - do not return rows from the 'one' table if ANY row in the 'many' table equals X

  21. 21

    MySQL LEFT JOIN is returning just one row with a where condition on the right table

  22. 22

    How to do this query in MySQL which one should I use using left join or right join or inner join?

  23. 23

    How to search a table using JS and return only the matching row?

  24. 24

    Mysql join table result as one row

  25. 25

    Trying to do a LEFT JOIN on two tables but want only one from the RIGHT TABLE

  26. 26

    MySQL returning only one row (most recent one)

  27. 27

    MySQL - if row is duplicate, return only the first one

  28. 28

    Adding entries from multiple MySQL tables using one single SQL join statement, but only if there are entries available in the second table

  29. 29

    Select MySQL results based on most current row in join table

HotTag

Archive