SELECT * FROM service_table AS a
LEFT JOIN service_fib_table AS b ON a.service_no=b.service_no ;


How about adding one more further conditional JOIN in one statement above.

service_fib_table.fib_id=service_fib_port_table.fib_id

It means there is a hierarchy 
service_table->service_fib_table->service_fib_port_table.

-----Original Message-----
From: sqlite-users-bounces at mailinglists.sqlite.org 
[mailto:sqlite-users-boun...@mailinglists.sqlite.org] On Behalf Of Richard Hipp
Sent: Tuesday, September 22, 2015 4:35 PM
To: General Discussion of SQLite Database
Subject: Re: [sqlite] get the data anyway no matter what the entry of the 
second table is existing or not

On 9/22/15, John McKown <john.archie.mckown at gmail.com> wrote:
> On Tue, Sep 22, 2015 at 3:15 PM, ChingChang Hsiao <
> ChingChang.Hsiao at overturenetworks.com> wrote:
>>
>> How can I write in one statement to get the service_table data no
>> matter what the entry of service_fib_table is existing or not.
>>
>
> SELECT * FROM service_table AS a
> LEFT JOIN service_fib_table AS b
> WHERE a.service_no = b.service_no
> ;

Close, but not quite right.  The conditional needs to go inside an ON clause, 
not in the WHERE clause, since if it appears in the WHERE clause the 
b.service_no will be NULL and the test will fail for cases where 
service_fib_table is missing.

SELECT * FROM service_table AS a
LEFT JOIN service_fib_table AS b ON a.service_no=b.service_no ;

--
D. Richard Hipp
drh at sqlite.org
_______________________________________________
sqlite-users mailing list
sqlite-users at mailinglists.sqlite.org
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users


This email and attachments may contain privileged or confidential information 
intended only for the addressee(s) indicated. The sender does not waive any of 
its rights, privileges or protections respecting this information. If you are 
not the named addressee, an employee, or agent responsible for sending this 
message to the named addressee (or this message was received by mistake), you 
are not authorized to read, print, retain, copy or disseminate this message or 
any part of it. If received in error, please notify us immediately by e-mail, 
discard any paper copies and delete all electronic files of the email.

Computer viruses can be transmitted via email. The recipient should check this 
email and any attachments for viruses. Email transmission cannot be guaranteed 
to be secured or error-free as information could be intercepted, corrupted, 
lost, destroyed, arrive late or incomplete, or contain viruses. The sender 
accepts no liability for any damage caused by any transmitted viruses or errors 
or omissions in the contents of this message.

Overture Networks, Inc. 637 Davis Drive, Morrisville, NC USA 27560 
www.overturenetworks.com

Reply via email to