I am having four mysql tables
Table 1, t_source:
+--------+-------+
| cindex | cname |
+--------+-------+
Table 2, t_language:
+--------+-------+
| cindex | cname |
+--------+-------+
Table 3, r_src_cat:
+-----------+-----------+-------+
| src_index | lan_index | clink |
+-----------+-----------+-------+
Table 4, r_source:
+-----------+-----------+-------+
| src_index | lan_index | clink |
+-----------+-----------+-------+
I want to retrieve clink, source and language indexes or name from table 3 - r_src_cat which are not present in table 4 - r_source. For this I am using following query:
SELECT
r_src_cat.clink,
t_source.cname,
t_language.cname
FROM r_src_cat, r_source, t_source, t_language
WHERE r_src_cat.c_src_index != r_source.c_src_index
AND r_src_cat.c_lan_index != r_source.c_lan_index
AND t_source.cindex = r_src_cat.c_src_index
AND t_language.cindex = r_src_cat.c_lan_index
ORDER BY r_src_cat.clink;
This is giving me wrong results. There are about 12 records missing from r_source, but result is giving me like infinite number of any record displaying same record multiple times and that record is present in table.
Please rectify my query.
Thanks
EDIT---
Foreign Key Relations
Table 3, r_src_cat.src_index=>t_source.cindex Table 3, r_src_cat.lan_index=>t_language.cindex
Table 4, r_source.src_index=>t_source.cindex Table 4, r_source.lan_index=>t_language.cindex
EDIT 2----
By different suggestions, i run this query
SELECT
r_src_cat.c_src_index,
r_src_cat.c_lan_index
FROM r_src_cat
LEFT JOIN r_source ON r_src_cat.c_src_index = r_source.c_src_index
WHERE r_source.c_src_index IS NULL;
Result
352 0
352 0
352 0
352 0
352 0
352 0
352 0
352 0
352 0
352 0
352 0
338 0
338 0
569 0
569 0
569 0
This result is correct, but not complete. For e.g.,I run following query on table 3:
SELECT
r_src_cat.c_src_index,
r_src_cat.c_lan_index
FROM r_src_cat
WHERE r_src_cat.c_src_index = 535 AND r_src_cat.c_lan_index = 11;
It is showing a result set with one row.
Now the same query on table 4 - r_source:
SELECT
r_source.c_src_index,
r_source.c_lan_index
FROM r_source
WHERE r_source.c_src_index = 535 AND r_source.c_lan_index = 11;
It returns and empty return set.
So combination 535,11 is present in table-3, but not in table 4. But the same combination is not present in running the Left Join query on table 3 & 4 mentioned above.