i have following tables in mysql:
table a:
+-------+-------------+------+-----+---------+-------+ | field | type | null | key | default | | +-------+-------------+------+-----+---------+-------+ | sid | varchar(50) | yes | | null | | | type | int(11) | yes | | null | | +-------+-------------+------+-----+---------+-------+
table b:
+---------+-------------+------+-----+---------+-------+ | field | type | null | key | default | | +---------+-------------+------+-----+---------+-------+ | channel | varchar(20) | yes | | null | | | sid | varchar(50) | yes | | null | | | type | varchar(20) | yes | | null | | +---------+-------------+------+-----+---------+-------+
i want find rows have entry in b same sid. tried following join command:
select a.sid join b on a.sid=b.sid;
this query never gives me answer. tabe has 465420 entries , table b has 291326 entries.
why not work? there many entries? or have fact have no primary keys assigned?
your query fine. appear need index. suggest b(sid)
.
you can write query as:
select a.sid exists (select 1 b a.sid = b.sid);
this not affect performance -- unless there lots of duplicates in b
-- eliminate issues caused duplicates in b
.
Comments
Post a Comment