problem in query

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
eshban
Forum Contributor
Posts: 184
Joined: Mon Sep 05, 2005 1:38 am

problem in query

Post 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
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post 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?
User avatar
CoderGoblin
DevNet Resident
Posts: 1425
Joined: Tue Mar 16, 2004 10:03 am
Location: Aachen, Germany

Post 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
eshban
Forum Contributor
Posts: 184
Joined: Mon Sep 05, 2005 1:38 am

Post 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
Post Reply