return ename and dname from emp and dept tables [Resolved]

Posted by Packs under Sql Server on 9/21/2012 | Points: 10 | Views : 1081 | Status : [Member] | Replies : 3
hello,
consider the regular emp and dept tables present in oracle by default,

i want sql query which gives me the name of emp from emp table and dname from dept table
Example:

CLARK ACCOUNTING
WARD RESEARCH

and so on.

Thanks and Regards.




Responses

Posted by: Tanujad on: 9/21/2012 [Member] Starter | Points: 50

Up
0
Down

Resolved
Use a INNER join for Employee and Department tables --

SELECT Emp.EmpName,Dept.DeptName

FROM Employee AS Emp
INNER JOIN Department Dept
ON Emp.DeptId = Dept.DeptId


Please mark it as answer if this resolves your query.

Thanks
Tanuja
(If this content helped you, Please mark it as Answer)

Packs, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Vasanthmvp on: 9/21/2012 [Member] Starter | Points: 25

Up
0
Down
Hi, this can be done using joins.
Here i consider two tables Department and Employee. They are in a relation ship. Primary key(Department_ID) of Department Table is set as a foreign key of Employee table with Department_ID as column name.

SELECT E.FIRST_NAME, D.Name FROM EMPLOYEE E JOIN DEPARTMENT D ON E.DEPARTMENT_ID = D.Department_ID

Explanation: Join two tables Employee and Department on the department_id column, filter the columns which you want.


Regards,

Awesome Coding !! :)

Packs, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Hariinakoti on: 9/21/2012 [Member] Starter | Points: 25

Up
0
Down
Hi Packs,
u can use inner joins for this query
u need common columns in both table.for suppose u hv dept id is common in both tables.u can take like alias names.then u can use it like below.

select e.empname,d.deptname from employtable e inner join depttable d on e.deptid=d.deptid



Thanks & Regards
Hari

Packs, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response