开发者

i want two columns value in different table in mysql and each table i apply different condition

开发者 https://www.devze.com 2023-02-11 19:18 出处:网络
i have two table. table1 and table2.each table is having three columns. each table columnsname is different.i apply the query fortable .i want one columns value for table1

i have two table. table1 and table2.each table is having three columns. each table columnsname is different.i apply the query for table .i want one columns value for table1 and i want 开发者_Go百科two columns value for table2.i want to write one query for each table and apply different condition for each table.but ,i want to result in only one query


You can concatenate to results with union

select col1 as A, col2 as B, col3 as C from table1 where col1 = 'foo'
union all
select colA as A, colB as B, colC as C from table2 where colB = 'bar'


use joins , it can be retrived

select table1.colname,table2.colname from table1, table2 where table2.colname=table2.colname.


SELECT tbl1.columnName,tbl2.columnName1,tbl2.columnName2 FROM table1 tbl1 OUTER APPLY ( SELECT columnName1,columnName2 FROM table2 WHERE table2.field_fk = tbl1.filedId )tbl2

0

精彩评论

暂无评论...
验证码 换一张
取 消