Clause where in mysql -
i have 2 tables.
table db1 , db2
db1 +-----------+------------+ | id | namedb | +-----------+------------+ | 1 | name1 | +-----------+------------+ | 2 | name2 | +-----------+------------+ | 3 | name3 | +-----------+------------+
db2
+------------+------------+-------------+----------------------+ | id | name | id_db1 | date | +------------+------------+-------------+----------------------+ | 1 | test1 | 1 | 2013-05-10 10:00:00 | +------------+------------+-------------+----------------------+ | 2 | test2 | 1 | 2013-05-10 11:00:00 | +------------+------------+-------------+----------------------+ | 3 | test3 | 1 | 2013-05-10 11:10:00 | +------------+------------+-------------+----------------------+ | 4 | test4 | 1 | 2013-05-10 11:40:00 | +------------+------------+-------------+----------------------+
my query this:
select a.namedb, b.name db1 left join db2 b on b.id_db1 = a.id date_format(b.name, '%y-%m-%d') = '2013-05-10'
i need return related day, not related must appear...
something like
+------------+------------+ | namedb | name | +------------+------------+ | name1 | test1 | +------------+------------+ | name1 | test2 | +------------+------------+ | name1 | test3 | +------------+------------+ | name1 | test4 | +------------+------------+ | name2 | null | +------------+------------+ | name3 | null | +------------+------------+
any idea ?
try this
select a.namedb, b.name db1 left join db2 b on b.id_db1 = a.id , date_format(b.date, '%y-%m-%d') = '2013-05-10'
if use columns left outer joined tables in clause behaves inner join
Comments
Post a Comment