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