Thursday, 16 May 2013

in commit and rollback which one is fast.


commit is faster than rollback because in commit, we simply change logs but in rollback we read logs, change logs and need to change data.

drop vs delete vs truncate

Drop:


  1. Drop is DDL operation. 
  2. IN drop, a table delete all data and table itself.
  3. we can not use rollback and commit.

Delete vs Truncate:
  1. Delete is DML operation while truncate is DDL operation.
  2. IN delete, we can use where condition but not in truncate. truncate delete all rows.
  3. Delete is slower than truncate.
  4. In delete, we can rollback but not in truncate because in delete, data is not permanent delete but in truncate, data is permanent deleted.
  5. In delete we need to use commit for permanent delete.
  6. When we do delete then it make a table for rollback.

Friday, 3 May 2013

nth highest data

SELECT * FROM table_name order by column_name asc limit x, y;


y->how many record do you want to fetch
x->in records which one do you want to select as for
second x = 1
for third x = 2

i have 15 record i want third highest salary then
select * from table_name order by salary desc limit 2,1