Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Database > SQL Language
|
SQL Language SQL Language discussions not specific to a particular RDBMS program or vendor.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Language section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 23rd, 2005, 05:55 AM
Authorized User
 
Join Date: Sep 2004
Posts: 36
Thanks: 0
Thanked 0 Times in 0 Posts
Default SQL join problem

Hi,

I need to check if the same ID exists in all tables, so I am using a join, but I have 2 tables (Employment, Education) where the ID is not a primary key and the ID appears several times in these tables.

So I just need to check if the ID appears once, do you know how I can do this?

So far I have the SQL below but it doesnt work, as you can see there are 12 rows when I want to only get 2

Any help would be much appreciated.

----------------SQL--------------------

SELECT loginid, pdloginid, eloginid, EOloginid, rloginid, sloginid, edloginid
FROM login, personaldetails, employment, equalopps, referee, education, skills
WHERE (login.loginid = personaldetails.pdloginid
AND login.loginid = education.edloginid AND login.loginid = equalopps.EOloginid
AND login.loginid = referee.rloginid
AND login.loginid = employment.eloginid AND login.loginid = skills.sloginid)
----------------------------------------

RESULT
11 11 11 11 11 11 11
11 11 11 11 11 11 11
11 11 11 11 11 11 11
11 11 11 11 11 11 11
11 11 11 11 11 11 11
11 11 11 11 11 11 11
11 11 11 11 11 11 11
11 11 11 11 11 11 11
11 11 11 11 11 11 11
2 2 2 2 2 2 2
2 2 2 2 2 2 2
2 2 2 2 2 2 2


 
Old May 23rd, 2005, 06:27 AM
Authorized User
 
Join Date: Sep 2004
Posts: 36
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks Ive sorted this now using the following code:

SELECT loginid
FROM login, equalopps, skills, referee, personaldetails
WHERE loginid IN (SELECT edloginid FROM education)
AND loginid IN (SELECT eloginid FROM employment)
AND loginid = equalopps.EOloginid
AND loginid = skills.sloginid
AND loginid = referee.rloginid
AND loginid = personaldetails.pdloginid

 
Old May 26th, 2005, 08:27 AM
Authorized User
 
Join Date: Jun 2003
Posts: 95
Thanks: 0
Thanked 0 Times in 0 Posts
Default

..or you could use a GROUP BY statement.

Gert






Similar Threads
Thread Thread Starter Forum Replies Last Post
SQL INNER JOIN problem lawsoncobol Access VBA 1 August 17th, 2006 02:29 PM
My SQL, ASP, and Inner Join Knuckles2003 Classic ASP Databases 0 October 31st, 2005 02:24 AM
SQL Join mattastic SQL Server 2000 9 April 21st, 2005 10:27 AM
Oracle 8i inner join and left join problem puteri_84 Oracle 2 August 19th, 2004 07:14 AM
SQL Inner Join Problem tp194 Classic ASP Databases 2 July 8th, 2003 09:59 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.