sql server - Shaping dataset in MySQL with a multiple inner join -


i learning mysql , working dummy tables set example online.

the code create tables wasn't given, end result of should like, did best re-create them. i know design isn't ideal - i'd rather use enum customer_info.state column, , type of datetime getdate() dates, example, haven't had success (more appropriate setups) yet i'm working on joins first, they're relevant job. i'll fine-tuning on design later (my job involve lot of querying , joining, not lot of db design, although i'd learn better habits/skills in arena).

i practicing inner join, , have joined 3 tables, result set isn't shaped way i'd like.

currently, 3 tables are:

customer_info (customerid int not null, firstname varchar(20) not null, lastname varchar(20) not null, city varchar(25), state varchar(2))  purchases (customerid int not null, order_month_day varchar(10), order_year int not null, item varchar(50) not null, quantity int not null, price float not null)  customer_favorite_colors (customerid int not null, favorite_color varchar(20) not null) 

i put query join 3 tables , display of particular columns:

select customer_info.customerid, customer_info.firstname, customer_info.lastname, customer_info.city, customer_info.state, purchases.item, customer_favorite_colors.favorite_color  customer_info  inner join purchases on customer_info.customerid = purchases.customerid  inner join customer_favorite_colors on purchases.customerid = customer_favorite_colors.customerid  order customer_info.customerid; 

and result set lists looking for, except it's formatted like:

these results getting:

so, how can ask sql show me each of these fields, more like:

these results achieve:

i think has using distinct, can't life of me figure out how make work.

also, if there differences in solution in mysql vs sql server 2012, helpful (we use sql server 2012 @ work).

what if add group by existing query like

    select customer_info.customerid, customer_info.firstname,     customer_info.lastname, customer_info.city, customer_info.state,    group_concat( purchases.item), customer_favorite_colors.favorite_color     customer_info     inner join purchases on customer_info.customerid = purchases.customerid     inner join customer_favorite_colors      on purchases.customerid = customer_favorite_colors.customerid     group customer_info.customerid, customer_info.firstname,     customer_info.lastname, customer_info.city,      customer_info.state, customer_favorite_colors.favorite_color     order customer_info.customerid; 

Comments

Popular posts from this blog

PHP DOM loadHTML() method unusual warning -

python - How to create jsonb index using GIN on SQLAlchemy? -

c# - TransactionScope not rolling back although no complete() is called -