php - Complex MySQL join with dynamic where -
here 2 tables i'm trying join...
name: notifications ------------------------------------------- content | position | member | contenttype ------------------------------------------- test | manager | testera | email test b | manager | testera | email test c | manager | testera | sms ------------------------------------------- name: position ----------------------------------------------- position | member | getsemail | getssms ----------------------------------------------- manager | testera | 1 | 0 employee | testerb | 0 | 1 -----------------------------------------------
i return rows "notifications" table member "testera", , contenttype "position" table equal "1". above table data, want first 2 rows "notifications" returned since contenttype of "email" allowed in position table.
is possible table structure?
try:
select n.* notifications n join position p on n.member = p.member , case n.contenttype when 'email' p.getsemail when 'sms' p.getssms end = 1 n.member = 'testera'
sqlfiddle here.
Comments
Post a Comment