Pages

Showing posts with label no. Show all posts
Showing posts with label no. Show all posts

Tuesday, November 18, 2014

Mysql Puzzle(Left Join)-Take out those department who have no employees assigned to it

EMP
EMPNO   ENAME    DEPTNO

DEPT
DEPTNO   DNAME
 
 
1st Way using Subquery
 
SELECT D.DNAME
FROM DEPT D
WHERE 
NOT EXISTS (SELECT * FROM EMP E WHERE D.DEPTNO = E.DEPTNO) 

2nd way using Left Join
 
SELECT D.DNAME
FROM DEPT D
LEFT JOIN EMP E ON D.DEPTNO = E.DEPTNO
WHERE E.DEPTNO IS NULL 

Saturday, December 1, 2012

Running a transaction in phpmyadmin


The problem with PHPmyAdmin is that all the lines have to be one command so it is not easy to demonstrate.

But if you run a transaction as follows it will not commit though the response says a different story

BEGIN;# MySQL returned an empty result set (i.e. zero rows).

UPDATE PRODUCTS_TMP
SET COST = 70
WHERE PROD_ID = '11235';# 1 row affected.

rollback;# MySQL returned an empty result set (i.e. zero rows).