php - Mysqli Getting Multiple Values from Multiple Tables -
i'm struggling figure out, , it's pretty simple can't work. using php/mysqli i'm trying data 2 tables, while first table have basis everything, second table may or may not have data matches first table's data, need second table return empty values. example...
first table 'cust':
customerid name school ------------------------------------------ 1623 bob smith bon 1785 betty davis foot 1854 john miller beck 1547 kate lake bon
second table 'ybk':
customerid frame type ------------------------------------------ 1623 001 cc 1854 012 cc
what these 2 tables bit variable between 2 things...
1) if want select school first table (for example cust.school='bon') result back:
customerid name school frame type --------------------------------------------------------- 1623 bob smith bon 001 cc 1547 kate lake bon
2) or, if select everything, result back:
customerid name school frame type --------------------------------------------------------- 1623 bob smith bon 001 cc 1785 betty davis foot 1854 john miller beck 012 cc 1547 kate lake bon
right now, when try different versions of select statement results in both tables instead of cust fields returning ybk ones if exist well. help! thank you!
this simple left join:
select * cust left join ybk using (custid) school='bon'; # custid, name, school, frame, type '1547', 'kate lake', 'bon', null, null '1623', 'bob smith', 'bon', '001', 'cc'
and
select * cust left join ybk using (custid); # custid, name, school, frame, type '1547', 'kate lake', 'bon', null, null '1623', 'bob smith', 'bon', '001', 'cc' '1785', 'betty davis', 'foot', null, null '1854', 'john miller', 'beck', '012', 'cc'
left join return rows first table in join, , fill null absent columns no matching row available in second table. rows matched on columns in using
clause, helpfully coalesces matched columns in resulting output.
the full syntx given in mysql manual here
Comments
Post a Comment