mysql - Select from two tables without primary key but same three column field in sql -
my 2 tables has no primary key have same 3 column field.i select 2 tables , come out result following:
table1:
no code row price 001 0001 1 100 001 0001 2 200 002 0001 1 300
table2:
no code row qty date 001 0001 1 10 2016 001 0001 2 20 2017
result table:
no code row price qty date row2 001 0001 1 100 10 2016 1 001 0001 1 100 10 2016 2 001 0001 2 200 20 2017 1 001 0001 2 200 20 2017 2
my sql:
select t2.no,t2.code,t2.row,t1.price,t2.qty,t2.date,t1.row row2 table1 t1 join table2 t2 on t1.no = t2.no , t1.code = t2.code order t2.code,t1.row
i want result come out this:
no code row price qty date row2 001 0001 1 100 10 2016 1 001 0001 2 200 20 2017 2
what should write sql? please advice me.. i'm new sql. if modify query this:
select t2.no,t2.code,t2.row,t1.price,t2.qty,t2.date,t1.row row2 table1 t1 join table2 t2 on t1.no = t2.no , t1.code = t2.code , t1.row = t2.row order t2.code,t1.row
it comes out nothing... please me.
thanks in advanced.
using left join solve problem.
select t2.no,t2.code,t2.row,t1.price,t2.qty,t2.date,t1.row row2 table2 t2 left join table1 t1 on t1.no = t2.no , t1.code = t2.code , t1.row = t2.row order t2.code,t1.row
Comments
Post a Comment