I have to compare 2 columns in mysql which has varchar data type. But there are some data which has leading '0' which is creating problem while comparing.
For ex: I have to compare between '02653' and '2653' which are actually equal, but here my query fails and gives different result.
Please suggest any idea what should be the right query for this.
I have tried to run like this
SELECT DISTINCT table1.store_id
FROM table2
WHERE
CONVERT('first_column' AS INTEGER) = CONVERT('second_column' AS INTEGER)
Showing this error
** for the right syntax to use near AS INTEGER **
convert the varchar to integer and then compare
...
WHERE CONVERT(column1 AS INTEGER) = CONVERT(column2 AS INTEGER)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With