mysql - inner join display list of sales by customer -
i need display list of sales customer, showing customer id, customer’s name, name of product bought customer, , date of sale , sorted customer id..
here customer table structure
create table customer (cust_id int not null auto_increment primary key ,forename char(10) not null ,surname char(10) not null ,phone char(15) null );
here sales table structure
create table sales (cust_id char(6) not null ,prod_id char(8) not null ,quantity smallint null ,date_of_sale null ,primary key(cust_id,prod_id) );
thank you.
products table
this give list of customers, uses left joins - means results show customers have no sales customers sales - information want know.
select c.cust_id, c.forename, c.surname, p.prod_name, s.date_of_sale customers c left join sales s on s.cust_id = c.cust_id left join products p on p.prod_id = s.prod_id order c.cust_id asc
if want see customers have sales - change left
inner
.
select c.cust_id, c.forename, c.surname, p.prod_name, s.date_of_sale customers c inner join sales s on s.cust_id = c.cust_id inner join products p on p.prod_id = s.prod_id order c.cust_id asc
Comments
Post a Comment