mySQL DATE_FORMATE with CONCAT funtion not working

I have two different tables and when I am trying to LEFT join it not working, I think I am using the right function to achieve the, even searched on google but did not get the expected output.
in return I am getting a ‘NULL’ value, Please help.

table1

ID  |  y_m
--------------
1   | 2023-04
2   | 2023-05

table2

ID  |  month  |  year
--------------------------
1   | 2023     | 04
2   | 2023     | 05
SELECT * FROM table2 LEFT JOIN table1 ON table1.y_m = DATE_FORMAT(CONCAT_WS('-', table2.year, table2.month) WHERE table2.year = 2023 AND table2.month = 05;

but this above MYSQL not working in myPHPAdmin
Please how to resolve this -

Remove the date format and only use the concatenation and it should work

it should, provided you switch the columns

SELECT * 
  FROM table2 
LEFT OUTER
  JOIN table1 
    ON table1.y_m = CONCAT_WS('-', table2.month, table2.year) 
 WHERE table2.month = 2023 
   AND table2.year = 05

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.