Solved

Select Query

Posted on 2000-05-15
8
155 Views
Last Modified: 2010-05-02
I have a candidates table Linked to a Language_Link table.
In the Language_Link table I have 2 columns, dsLanguageId and dsCandidateID.
I want to do get all the candidates who speak English and afrikaans what would the select query look like
0
Comment
Question by:JohnRock
  • 3
  • 2
  • 2
  • +1
8 Comments
 
LVL 4

Expert Comment

by:Jeremy_D
ID: 2809792
SELECT *
 FROM Candidates
  INNER JOIN Language_Link ON Candidates.dsCandidateID = Language_Link.dsCandidateID
 WHERE Language_Link.dsLanguageID = 'EN' Or Language_Link.dsLanguageID = 'AF'

You'll have to change the 'EN' and 'AF' in the where-clause to reflect the data in your Language_Link Table (could be a string like these or a numerical ID, depending on how you designed this table).
0
 
LVL 4

Expert Comment

by:Jeremy_D
ID: 2809795
Sorry, If you want everyone that speaks English *and* Afrikaans then the "OR" in the WHERE-clause should be an "AND" of course.

Sorry, early monday morning and all that :)
0
 

Accepted Solution

by:
Ryanc earned 90 total points
ID: 2809802
select  A.dsCandidateID
 
from  dsCandidates as A,
        dsLanguage as B,
        dsLanguage_Link as C
 
where A.dsCandidateID = C.dsCandidateID
and B.dsLanguageID = C.dsLanguageID
and C.dsLanguageID in (select dsLanguageId from dsLanguage as Z where Z.dsLanguageID = 1 or Z.dsLanguageID = 4 or Z.dsLanguageID = 6 or Z.dsLanguageID = 8)
 
group by A.dsCandidateID having count(*) = 4
order by A.dsCandidateID
0
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 

Expert Comment

by:Ryanc
ID: 2809811
sorry Jeremy,

if you change the OR to the AND, what will happen is that SQL will look for A SINGLE RECORD in the Language_Link table with a value of 'En' AND 'Afr' - clearly such a record will never exist ...

check my comment for the workable solution ...

cheers
Ryan
0
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 2810290
SELECT *
 FROM Candidates
  INNER JOIN (
select distinct dsCandidateID from
Language_Link
 WHERE Language_Link.dsLanguageID = 'EN' Or Language_Link.dsLanguageID = 'AF'
) AS Language_Link
ON Candidates.dsCandidateID = Language_Link.dsCandidateID


0
 

Author Comment

by:JohnRock
ID: 2810327
Adjusted points from 50 to 90
0
 

Author Comment

by:JohnRock
ID: 2810337
Comments to AngelIII.
Your query brings back everyone that speaks english or afrikaans, which is incorrect. I only want the people that speak Eng and Afr.
0
 
LVL 4

Expert Comment

by:Jeremy_D
ID: 2810601
Having trouble posting comments. Third attempt:

It's usually faster (given the right indexes) to use a second join in stead of a sub-query, like this (pending other 'monday-issues' :o) ):

SELECT *
 FROM Candidates
  LEFT JOIN Language_Link AS l1 ON Candidates.dsCandidateID = l1.dsCandidateID
  LEFT JOIN Language_Link AS l2 ON Candidates.dsCandidateID = l2.dsCandidateID
 WHERE l1.dsLanguageID = 'EN' AND l2.dsLanguageID = 'AF'

0

Featured Post

ScreenConnect 6.0 Free Trial

At ScreenConnect, partner feedback doesn't fall on deaf ears. We collected partner suggestions off of their virtual wish list and transformed them into one game-changing release: ScreenConnect 6.0. Explore all of the extras and enhancements for yourself!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question