I have a table T1, which contains which contains columns (A , B, C ,D) in which A is PK.
And I have some more tables. And I want to get some data from these tables. I get the data as per my sql query from these tables. Sql query (query1) is as follows
select t3.col1 as A, t3.col4 as F, t4.col as H
from t3, t4
where t3.col1 = t4.col2;
Now I want to get data from Table T1 and above query1 result.
select B , C , D , F, H
from T1, Temp
where t1.A = Temp.A;
where Temp is the above sql query1 result.
How I can achieve this?
Any suggestions.
try this
SELECT t1.B as B, t1.C as B, t1.D as D, t3.col4 as F, t4.col as H
FROM t1, t3, t4
WHERE t1.A=t3.col1 AND t3.col1=t4.col2
I'd suggest using explicit join as in:
select t1.B, t1.C, ..., t3.col1 as A, t3.col4 as F, t4.col as H
from t3
join t4
on t3.col1 = t4.col2
join t1
on t1.A = t3.col1;
Use inner join
consider this exapmle
lets say two table 1st one is "Order" and 2nd is "Customer"
SELECT Orders.OrderID(table_name.column_name), Customers.CustomerName(table_name.column_name), Orders.OrderDate(table_name.column_name) FROM Orders(1st table_name) INNER JOIN Customers(2nd table_name) ON Orders.CustomerID=Customers.CustomerID(Must be matching field for joining);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.