Hi, I recently tried to get employee names and their dept names without a join condition, this query, although succeeds, I can't figure how it works. please help. select ename,(select dname from dept where deptno=e.deptno) from emp e;

Youre using a Sub-query -- [(select dname from dept where deptno = e.deptno)] -- to get around using a join clause like -- [FROM EMP E INNER JOIN DEPT D ON (D.DEPTNO = E.DEPTNO)] -- however, you are not actually getting away with not joining the two tables, youre just defining the join in a more complex method. For future coding of your queries it would be better to follow the guide line of Occams razor: "All things being equal, a simpler explanation is better than a more complex one."
To that end, a query that uses a JOIN clause to relate tables is easier to understand, than a query that tries to get around using a JOIN clause.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.