Tuesday 26 July 2016

difference between table in a single sql query

IF you have tables A and B, both with column C, here are the records, which are present in table A but not in B:
SELECT A.*
FROM A
    LEFT JOIN B ON (A.C = B.C)
WHERE B.C IS NULL
To get all the differences with a single query, a full join must be used, like this:
SELECT A.*, B.*
FROM A
    FULL JOIN B ON (A.C = B.C)
WHERE A.C IS NULL OR B.C IS NULL
What you need to know in this case is, that when a record can be found in A, but not in B, than the columns which come from B will be NULL, and similarly for those, which are present in B and not in A, the columns from A will be null.

how to delete duplicate records in sql in single query


create table Employee (id int, name varchar(50))

insert into Employee values (1,'raja')

insert into Employee values (2,'raja')

insert into Employee values (3,'krishna')

insert into Employee values (4,'krishna')

insert into Employee values (5,'ramana')

insert into Employee values (6,'prakash')

delete
from table T1, table T2
where T1.dupField = T2.dupField
and T1.uniqueField > T2.uniqueField

delete
from Employee T1, table T2
where T1.name = T2.name
and employee_id.id > T2.employee_id

Friday 8 July 2016

Executor.execute() vs ExecutorService.submit()

1) Both submit() and execute() methods are used to submit a task to Executor framework for asynchronous execution.

2) Both submit() and execute() can accept a Runnable task.

3) You can access submit() and execute() from the ExecutorService interface because it also extends the Executor interface which declares the execute() method.

Apart from the fact that submit() method can return output and execute() cannot, following are other notable differences between these two key methods of Executor framework of Java 5.

1) The submit() can accept both Runnable and Callable task but execute() can only accept the Runnable task.

2) The submit() method is declared in ExecutorService interface while execute() method is declared in the Executor interface.

3) The return type of submit() method is a Future object but return type of execute() method is void.

Read more: http://javarevisited.blogspot.com/2016/04/difference-between-ExecutorServie-submit-vs-Executor-execute-method-in-Java.html#ixzz4DooQVq5V