Solved

Problem with JOIN statement [Firebird]

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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
sql help 8 55
Sql Stored Procedure field variable 17 27
MySQL Query Using Up Memory 6 21
Mongo DB 18 34
CCModeler offers a way to enter basic information like entities, attributes and relationships and export them as yEd or erviz diagram. It also can import existing Access or SQL Server tables with relationships.
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…

816 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now