• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 220
  • Last Modified:

left outer join

file A = StudentID, Name,grade   file B= StudentID,AtRiskIndicator
In SQL how do I join file A and B so that my result set includes every row in file a and the AtRiskIndicator from file B only when the AtRiskIndicator = "High'
0
gmkrjs
Asked:
gmkrjs
1 Solution
 
gnoonCommented:
You may need a subquery in statement.

#Sql Server
select A.*, B2.AtRiskIndicator from A left outer join (select * from B where AtRiskIndicator = 'High') as B2 on A.StudentID = B2.StudentID

#MySql Server
select A.*, B2.AtRiskIndicator from A left join (select * from B where AtRiskIndicator = 'High') as B2 on A.StudentID = B2.StudentID

#Oracle
select A.*, B2.AtRiskIndicator from A, (select * from B where AtRiskIndicator = 'High') B2 where A.StudentID = B2.StudentID (+)
0
 
David ToddSenior DBACommented:
Hi,

SQL deals with tables, not files ...

Something like
select a.*
from fileA a
inner join fileB b
  on a.StudentID = b.StudentID
where b.AtRiskIndicator = 'High' -- presuming that indecator is a character type

HTH
  David

PS What database (and version) are you using?
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now