?
Solved

how to cater for null

Posted on 2006-06-21
9
Medium Priority
?
294 Views
Last Modified: 2006-11-18
I have 3 tables, linked using keys:

table1 link to table2
table1 link to table3

I need to select sths out of table 2 and 3, linking by 1.

Some content in 3 may not available, I want to get null intead.

Any suggestion? How to write the sql? using join?, I tried but failed.

0
Comment
Question by:turbot_yu
[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
  • 5
  • 4
9 Comments
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 16957414
you need to use LEFT JOIN

select *
from table1
inner join table2
  on table1.<field> = table2.<field>
left join table3
  on table1.<field> = table3.<field>
0
 

Author Comment

by:turbot_yu
ID: 16957451
The table 1 -> table 2 is also one -> many,

Does it need 'inner' or 'left'
0
 

Author Comment

by:turbot_yu
ID: 16957472
Table1:Source
ID
Name

Table2:Wave
ID
SourceID
Timestamp

Table3:eventLog
ID
SourceID
Timestamp
0
NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 16957474
if there will be at least one record in table2 for all rows in table1, inner join is fine. left join will work the same in that case.
0
 

Author Comment

by:turbot_yu
ID: 16957485
Table1:Source
ID
Name

Table2:Wave
ID
SourceID
Timestamp

Table3:eventLog
ID
SourceID
Timestamp
String

Table1: 1 record
Table2: 3 record
Table3: 2 record

I want result as

timestamp1 start
timestamp2 null
timestamp3 end
0
 

Author Comment

by:turbot_yu
ID: 16957552
SELECT wf.TimestampSourceLT,wf.Quantity, wf.FirstFracOfASec, wf.SamplingFrequency, wf.Samples, es.String
FROM
ION_Data.dbo.Source s
inner join  ION_Data.dbo.vWFLogChannelValue wf
on(s.name = wf.sourcename)
left outer join ION_Data.dbo.EventLog el      
on( s.id=el.sourceid )
left outer join ION_Data.dbo.EventString es      
on(el.CauseValueID=es.ID)
where
wf.Quantity='I4 Waveform'
AND wf.TimestampSourceLT>'2006-06-19 18:45:05'
OR (wf.TimestampSourceLT='2006-06-19 18:45:05'
AND left(wf.FractionofASecond,8)>0.000000)
AND (es.String='Disturbance Start' or es.String='Transient Detected')
ORDER BY wf.TimestampSourceLT, wf.FractionofASecond;
0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 16957598
you have to move the conditions about the left joined table into the join condition:

SELECT wf.TimestampSourceLT,wf.Quantity, wf.FirstFracOfASec, wf.SamplingFrequency, wf.Samples, es.String
FROM ION_Data.dbo.Source s
inner join  ION_Data.dbo.vWFLogChannelValue wf
  on(s.name = wf.sourcename)
left outer join ION_Data.dbo.EventLog el      
  on( s.id=el.sourceid )
left outer join ION_Data.dbo.EventString es      
  on(el.CauseValueID=es.ID)
AND (es.String='Disturbance Start' or es.String='Transient Detected')
where
wf.Quantity='I4 Waveform'
AND wf.TimestampSourceLT>'2006-06-19 18:45:05'
OR (wf.TimestampSourceLT='2006-06-19 18:45:05'
AND left(wf.FractionofASecond,8)>0.000000)
ORDER BY wf.TimestampSourceLT, wf.FractionofASecond;
0
 

Author Comment

by:turbot_yu
ID: 16965691
Thanks, now null is there, but many recorder duplicate in results.
0
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 2000 total points
ID: 16967219
this is either due to
* missing join conditions
* solvable by adding "DISTINCT" or "GROUP BY" clause
0

Featured Post

Get real performance insights from real users

Key features:
- Total Pages Views and Load times
- Top Pages Viewed and Load Times
- Real Time Site Page Build Performance
- Users’ Browser and Platform Performance
- Geographic User Breakdown
- And more

Question has a verified solution.

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

In this blog post, we’ll look at how ClickHouse performs in a general analytical workload using the star schema benchmark test.
Backups and Disaster RecoveryIn this post, we’ll look at strategies for backups and disaster recovery.
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…

801 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