Solved

Problem with JOIN statement [Firebird]

Posted on 2009-05-17
3
500 Views
Last Modified: 2013-12-09
Having problems with a join statement. The code itself is working, but it's not showing up all the records I want.

Lag = Teams in the database
Spelare = Players in the database

The "join Spelare S on L.Klubb" is joining the teams in the two tables.
My problem however, is that not all team's are added into Lag L which makes them not show up.

The only results shown are where the players have a team that's also added into the table Lag. If the team is not added there it doesn't show up (probably because of the joined statement and the "where NOT L.Division = 'NHL') ?

I want all records but NOT L.Division = 'NHL' to show up, even the ones that doesn't have a team in the Lag table.

Should I use NULL somehow to identify the "unknown" teams or something?
select S.* from Lag L join Spelare S on L.Klubb = S.Klubb where NOT L.Division = 'NHL'  and S.Rattigheter is null and S.Alder > 17 and S.Alder < 30 order by (S.Off+S.Def) * (S.Potential*4) / (S.Alder*3) DESC

Open in new window

0
Comment
Question by:MerlaP83
[X]
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
  • 2
3 Comments
 
LVL 19

Expert Comment

by:NickUpson
ID: 24406002
 

Open in new window

you need right join, 

Open in new window

select S.* from Lag L right join Spelare S on L.Klubb = S.Klubb where NOT L.Division = 'NHL'  and S.Rattigheter is null and S.Alder > 17 and S.Alder < 30 order by (S.Off+S.Def) * (S.Potential*4) / (S.Alder*3) DESC

Open in new window


0
 

Author Comment

by:MerlaP83
ID: 24406785
Unfortunately that didn't work.

The problem seems to be with where NOT L.Division = 'NHL'. If I remove that line, then everything is showing up. But I need to use that line as well to filter out some players - and if the player's team is not added to Lag, then it seems to skip that player, which is wrong.
0
 
LVL 19

Accepted Solution

by:
NickUpson earned 250 total points
ID: 24406950
where ( L.Division <> 'NHL' or L.division is null)
0

Featured Post

More Than Just A Video Library

Train for your certification. Learn the latest DevOps tools. Grow your skillset to do better work.

At Linux Academy, we release new training modules every week so you'll always be up to date on the latest tech.

Question has a verified solution.

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

In this series, we will discuss common questions received as a database Solutions Engineer at Percona. In this role, we speak with a wide array of MySQL and MongoDB users responsible for both extremely large and complex environments to smaller singl…
Your data is at risk. Probably more today that at any other time in history. There are simply more people with more access to the Web with bad intentions.
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

695 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