MySQL: Query and join two tables

前端 未结 4 1802
灰色年华
灰色年华 2021-01-23 03:17

I have two tables that I believe I want to JOIN. I\'m very new to this and am not completely sure…

The first table is called venues with the variables <

4条回答
  •  日久生厌
    2021-01-23 04:01

    How about this?

    SELECT t1.*, t2.*
    FROM venue t1 JOIN venue_terms t2
    ON t1.id = t2.venue
    WHERE (t2.option = 1 AND t2.value = 10)
    

    NOTE: I believe option and value are of type INT.

    If they are of type varchar then change above query to

    SELECT t1.*, t2.*
    FROM venue t1 JOIN venue_terms t2
    ON t1.id = t2.venue
    WHERE (t2.option = '1' AND t2.value = '10')
    

    Update 1

    As per your new requirement, you will just need to add that condition with OR option as shown below.

    SELECT t1.*, t2.*
    FROM venue t1 JOIN venue_terms t2
    ON t1.id = t2.venue
    WHERE 
         (t2.option = 1 AND t2.value = 10)
         OR
         (t2.option = 3 AND t2.value = 14)
    

提交回复
热议问题