I have two table and I need a (LEFT/RIGHT/INNER) JOIN on two date fields.
The transactions
table has a timestamp data type. (with Adminer by the way I can read data in "human format", not in number, just as note for you).
Another one, the calendar
table, has a date
data type.
I'm going crazy trying to cast
/convert
the first timestamp
to the date
without success. The JOIN
does not JOIN
at all, like the two data are different type.
SELECT *
FROM transactions
RIGHT JOIN calendar ON calendar.day_date = DATE(transactions.dateTransaction)
I have 2 values in transactions
and 100 in calendar
, so I'm expecting 100 records -- 98 with NULL and 2 populated.
Of course this doesn't change also in:
SELECT *
FROM transactions
LEFT JOIN calendar ON calendar.day_date = DATE(transactions.dateTransaction)
or, also, with a double DATE
:
SELECT *
FROM transactions
LEFT JOIN calendar ON DATE(calendar.day_date) = DATE(transactions.dateTransaction)
Or also:
SELECT *
FROM calendar c
RIGHT JOIN transactions t ON c.day_date = DATE(t.dateTransaction)
SELECT *
FROM calendar c
LEFT JOIN transactions t ON c.day_date = DATE(t.dateTransaction)
I'm getting only the 2 records on transactions, I'm expecting ~100 (100 on calendar).
Or also with a FROM_UNIXTIME
.
transactions
table schema:
CREATE TABLE `transactions`
( `idTransactions` int(11) NOT NULL AUTO_INCREMENT,
`dateTransaction` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (`idTransactions`),
KEY `index_dateTransaction` (`dateTransaction`) USING BTREE
) ENGINE=MyISAM AUTO_INCREMENT=155731 DEFAULT CHARSET=utf8
calendar
table schema
CREATE TABLE `calendar`
( `day_date` date DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8