There are two tables in two different databases in same server. database table are as below.
I want to get records of table 2 where delivery_date (date only. It means 2023-01-25) is equal to logtime date in table 1. Delivery_date and logtime datetype is datetime. Result should be as below.
I tried as below
SELECT *
FROM Database2.table2 t2
INNER JOIN Database1.table1 t1
WHERE t2.delivery_date= t1.logtime AND t2.v_id='A001';
This is not getting what I want. how can I solve this.
>Solution :
You have to convert both date time values to date using the DATE-function:
SELECT *
FROM Database2.table2 t2
INNER JOIN Database1.table1 t1
on DATE(t2.delivery_date)= Date(t1.logtime) AND t2.v_id='A001';
If you do not do it, the complete date time value will be compared

