Select Query

Posted on 2000-05-15
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
Question by:JohnRock
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
  • +1

Expert Comment

ID: 2809792
 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).

Expert Comment

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 :)

Accepted Solution

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
Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.


Expert Comment

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 ...

LVL 143

Expert Comment

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


Author Comment

ID: 2810327
Adjusted points from 50 to 90

Author Comment

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.

Expert Comment

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) ):

 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'


Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Access query that references subform 5 49
vb6 connector to mongodb 2 160
Excel Automation VBA 19 115
how to Classify of email (pdf attachments) 7 56
Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

740 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