mysql - How to JOIN two tables when not using any Primary Keys? -
i'm trying join
2 tables using columns aren't either of tables respective primary keys:
select * tablea inner join tableb b on a.col5 = b.col5
yet above returning 0 results
though know sure there rows in table a
col5
values match values in col5
of table b
.
what doing wrong?
you query:
select * tablea inner join tableb b on a.col5 = b.col5;
has correct syntax join. if there matching values, return it. (or course, calling application , there errors either in application code or connection database, issue.)
some cases values same not:
- both values floats. same when printed out. bit @ end of value differs. never use floats equi-joins.
- one value number , other value string. conversion of 1 of values results in different value.
- one value date/time , other string. conversion of 1 of values results in different value.
- the values strings. differ in case. think
abc
sameabc1
, sql doesn't. - you have spaces or other "hidden" characters @ end of string.
and 2 more reasons can think of may not true in databases:
- one value char , other varchar (or wide versions of them). implicit spaces @ end of char make them different.
- one unicode string , other ascii string. 2 characters same not.
Comments
Post a Comment