php - MySql - Dynamic Table Selection with IF ELSE -



php - MySql - Dynamic Table Selection with IF ELSE -

does mysql got cover if else select table dynamically ?

the link here show's if value, how can if / if else can accomplish select table below :

for illustration dynamic table 'othertable'

select t1.etc,t2.etc,othertable.etc table1 t1,table2 t2, if(t1.value=3,table3,table4) othertable othertable.table1_id = t1.id

you accomplish union.

select t1.* table1 t1 bring together table_a ta on (...) t1.value = 3 union select t1.* table1 t1 bring together table_b tb on (...) t1.value = 2

for each row t1.value =3, bring together table_a done, each row t1.value = 2, table_b joined. union adds results together.

you need create sure 2 conditions mutually exclusive. if can't ensure this, can rid of duplicates in result set using union instead of union all.

php mysql dynamic relational-database

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -