开发者

Sort output from multiple tables

Query1(by combining table1, table 2): returns

SELECT t1.ID1,t1.Name
FROM table1 t1, table2 t2
WHERE t1.ID1=t2.ID;

ID1  Name

4      ppp
1      pqr
2      abc
3      xyz

Query2(using table 3, which stores IDs): returns

select ID from table3;

ID 
1
2
3
4

Combine Query1 & Query 2 & produce output as

ID Name

1  pqr
2  abc
3  xyz
开发者_开发问答4  ppp

ie main values are coming from 2 different values while sorted values(IDs) are stored in random order in third table.


something like:-

select t1.ID1,t1.Name from table1 t1, table2 t2 
LEFT JOIN table3 t3 ON t3.ID = t1.ID where t1.ID=t2.ID;
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜