mysql - SQL Join query to join 2 tables to get desired output -


i have 2 tables , need join them desired result. tried multiple types of joins no luck. please assist.below how tables looks like:

select * t1

productid, sequence, property 100, 1, size 100, 2, folder 100, 3, license 101, 1, usage 101, 2, duration 

select * t2

srno, productid, property, propertyvalue 1,    100, size, 10gb 2,    100, folder, /home/path 3,    101, usage, database 

i need join them following result:

srno, productid, sequence, property, propertyvalue 1     100         1         size      10gb 1     100         2         folder     1     100         3         license      2     100         1         size       2     100         2         folder    /home/path 2     100         3         license    3     101         1         usage      database 3     101         2         duration     

below sqls reproduce same tables:

create table t1 (productid int, sequence int, property varchar(255)) insert t1 values(100,1,'size'); insert t1 values(100,2,'folder'); insert t1 values(100,3,'license'); insert t1 values(101,1,'usage'); insert t1 values(101,2,'duration');  create table t2 (srno int, productid int, property varchar(255), propertyvalue varchar(255)) insert t2 values(1,100,'size','10gb'); insert t2 values(2,100,'folder','/home/path'); insert t2 values(3,101,'usage','database'); 

please assist how can write query?

select     table2.srno,     table1.productid,     table1.sequence,      table1.property,     table2.propertyvalue t1 table1   join t2 table2 on table1.productid = table2.productid 

Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -