MySQL: Determine if Date Exists in Multiple Tables -
i building monthly statistics form system. front end page of scheme shows either '+' if no statistics have been set month , [pencil glyphicon] if there have been statistics set.
the front end page looks similar (pencil glyph replaced pipe)
year 2014 jan feb mar apr may jun jul aug sep oct nov dec + + + | + | | | | | | | year 2013 jan feb mar apr may jun jul aug sep oct nov dec + + + + + | | | + | + |
...and on.
simple enough.
but problem not checking 1 table see if "month_id" field equals month; checking 7 different tables. 7 tables have mutual field "month_id".
if of 7 tables contain month_id matches current month, pencil glyph should shown. if not, '+'.
i don't need help generating html or php this, advice on if there effective way query database.
here's 1 solution:
select (select count(*) table1 month_id = month(curdate())) + (select count(*) table2 month_id = month(curdate())) + (select count(*) table3 month_id = month(curdate())) + (select count(*) table4 month_id = month(curdate())) + (select count(*) table5 month_id = month(curdate())) + (select count(*) table6 month_id = month(curdate())) + (select count(*) table7 month_id = month(curdate()));
if result greater 0, have @ to the lowest degree 1 matching row among 7 tables.
mysql
No comments:
Post a Comment