I have 2 tables I would like to left join together.
Table A has my reference data with ID of type integer.
Table B stores my data and one of the columns has a loose link to my reference table. This means it can hold the ID from the other table or some arbitrary text.
I would like to perform a query joining them together and displaying the data from reference table only if a record with matching ID is found.
A much simplified example (MCVE):
CREATE TABLE a
(
id INT
);
INSERT INTO a VALUES (5);
CREATE TABLE b
(
id VARCHAR(10)
);
INSERT INTO b VALUES ('5sdf');
I tried this query:
SELECT * FROM a LEFT JOIN b USING(id)
but the result is 5
, which is not what I expected because values are different - http://www.sqlfiddle.com/#!9/6c5965/1
I also tried with explicit ON
clause:
SELECT * FROM a LEFT JOIN b ON a.id=b.id
but this one was also joined. - http://www.sqlfiddle.com/#!9/6c5965/2/0
How can I join the two tables with columns of different data types without implicit casting?