Naganath
Naganath

Reputation: 31

sql query for retrieving data from two tables

There are two tables as below

employee table: empid, empname, deptid

department table: deptid, deptname

then write query to "list all employees for dept name=computer"

Upvotes: 1

Views: 18704

Answers (3)

Laxmikant Dhond
Laxmikant Dhond

Reputation: 11

SELECT empname, deptname 
from employee, department
where employee.deptid=department.deptid
and department.deptname='computer';

Computer must be case sensitive as per your values in your table

Upvotes: 1

kufudo
kufudo

Reputation: 2833

SELECT e.empname, deptname
FROM employee e
    INNER JOIN department d
    ON e.deptid = d.deptid
GROUP BY emptname, deptname

Upvotes: 0

John Woo
John Woo

Reputation: 263733

this should be pretty straight forward,

SELECT  a.empid, a.empname, b.deptname
FROM    employee a
        INNER JOIN department b
            ON a.deptid = b.deptid
ORDER   BY  b.deptname, a.empname

To further gain more knowledge about joins, kindly visit the link below:

Upvotes: 3

Related Questions