Solved

Problem with JOIN statement [Firebird]

Posted on 2009-05-17
3
498 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
  • 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
These days, all we hear about hacktivists took down so and so websites and retrieved thousands of user’s data. One of the techniques to get unauthorized access to database is by performing SQL injection. This article is quite lengthy which gives bas…
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…

730 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