Page 1 of 1

problem in query

Posted: Mon Sep 04, 2006 6:16 am
by eshban
hello

i have a little problem,


there are 2 tables hain
first table contains main 5000 records
and second contains 2500 records.

i want to fetch those records of table two which are not present in table 1.

table1 structure:
autoid:
userid:
it contains values from 1-10

table2 structure
autoid:
userid_pass:
it contain values 1,3,5,7

means our query gives the result as : 2,4,6,8,10

kindly make a valid query for this.

eshban





--
<a href="http://groups.google.com/group/eshbansworldofinfo" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">Join My Group</a>

--
<a href="http://www.GlitterMaker.com/">
<img src="http://graphics.GlitterMaker.com/8/219/ ... 418102.gif" border="0"></a><br>

Plz Rate My Picture At:
=================
http://www.ratedesi.com/view.php?id=172861&aim=%n

Posted: Mon Sep 04, 2006 7:05 am
by volka
Can be done with a LEFT/RIGHT JOIN and a WHERE clause that selects only those records with NULL fields on the dependant table.
What do you know about sql and JOINs?

Posted: Mon Sep 04, 2006 7:53 am
by CoderGoblin
or EXISTS

Code: Select all

SELECT DISTINCT * FROM table2
  WHERE NOT EXISTS (SELECT 1 FROM table1
                    WHERE table1.linkcol = table2.linkcol);
or something similar

Posted: Mon Sep 04, 2006 8:08 am
by eshban
no wrong query, cannot runs . it just display empty result.

i got the solution

SELECT
tech_customers.customerId FROM
tech_customers
WHERE
tech_customers.customerId Not In
(
SELECT
tech_auth_customers.customerId
FROM
tech_auth_customers where tech_auth_customers.customerId <> ''
)


anyway thanks