Reputation: 177
I have 2 tables in an SQL database. First table has columns as tabl1column1,table1column2,table1column3 and second table has table2column1,table2column2. I want to get the data of table2column1,table1column2,table1column3
select S_No,Employee_id,Employee_name from Employee_Details order by S_No
S_No must from dailyattendance table not from Employee_Details and Employee_id,Employee_name should be from Employee_Details table
This is my query. Please edit it or solve it as my requirement.
How to solve it?
Please help.
Upvotes: 0
Views: 62
Reputation: 1999
if there is is relationship between your tables you can use INNER JOIN
for it
select d.S_No, e.Employee_id, e.Employee_name
from Employee_Details e INNER JOIN
dailyattendace d
ON e.Employee_id= d.Employee_id order by S_No
rember this will work only if there is proper relation between e.Employee_id
and d.Employee_id
Upvotes: 0
Reputation: 429
SELECT d.S_No,e.Employee_id,e.Employee_name
FROM employee_details AS e, dailyattendace AS d
WHERE e.Employee_id= d.Employee_id Order By d.S_No
I don't see the second table but this is how you can do it. You can also use employee_details.S_No and table2.S_No but you write faster e.s_No than the whole table name.
Adapt to your query. In your query you only use one table but i wrote as you were using two
Upvotes: 1