How to fetch data from two different tables using between statement?

36 Views Asked by At

here Iam trying to fetch two table data based on one column 'createdon' and my statement is like below

"SELECT * FROM table1 INNER JOIN table2 ON table1.createdon = table2.createdon WHERE table1.createdon AND table2.createdon BETWEEN '$fromdate' AND '$todate' ORDER BY id"

would anyone correct me please, if Iam wrong

Thanks you......

1

There are 1 best solutions below

0
Barmar On

you shouldn't say table1.createdon AND table2.createdon. You only need to test one of them, since the ON condition requires both rows to have the same createdon value.

"SELECT * 
FROM table1 
INNER JOIN table2 ON table1.createdon = table2.createdon 
WHERE table1.createdon BETWEEN '$fromdate' AND '$todate'
ORDER BY id"