SQL query

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hai friends

I have a problem in writing query for composite primary key.

Problem -
1) clientid and dpid is composite primary ke
2) Master table has clientid and dpi
3) The new data i.e. Temp table (my temporary table) will also have the columns clientid and dpi

now I require a query to find the clientid's who are existing in Master table and not in Temp table

Thank you
 
Hello,

there are at least three alternatives to solve this problem. One is to use a
JOIN clause, second is the NOT IN and third the NOT EXISTS:
1.: SELECT master.clientid
FROM master LEFT JOIN temp ON (temp.clientid=master.clientid)
WHERE temp.clientid IS NULL
2. SELECT clientid FROM master WHERE clientid IS NOT IN (SELECT clientid
FROM temp)
3. SELECT clientid FROM master WHERE NOT EXISTS (SELECT * FROM temp WHERE
temp.clientid=master.clientid)

I hope, this helps. Maybe the syntax differs from DBMS to DBMS.

Sai Pavan said:
Hai friends,

I have a problem in writing query for composite primary key.

Problem --
1) clientid and dpid is composite primary key
2) Master table has clientid and dpid
3) The new data i.e. Temp table (my temporary
table) will also have the columns clientid and dpid
 
Back
Top