|
Main » 2012 » September » 03
Get duplicate records from table Select ename from tbemp a where a.eno!=(select Max(eno) from tbemp b where a.ename=b.ename)
Here eno denotes to employee number and ename denotes to employee name.
Category:
Database
|
Views:
2356
|
Added by:
Admin
|
Date:
2012-09-03
|
|
Without Data Select * INTO tbem1 from tbemp where 1=2
Why 1=2? Because none of the record could satisfy this condition i.e. 1=2. So no data would be copied into newly created table.
With Data Select * INTO tbemp2 from tbemp
With Condition Select * INTO tbemp3 from tbemp where depcod=102
Here depcod denotes to department code.
Category:
Database
|
Views:
2305
|
Added by:
Admin
|
Date:
2012-09-03
|
|
Select Alternate Row SQL Server
Their are many approaches to get alternate record from SQL server database table. Here i have discussed 2 approaches
1. Complex Query
2. Using Views
Complex Query: SELECT * from (SELECT ROW_NUMBER() OVER(ORDER BY Employee_id) as RowNumber, * from employees) T where t.RowNumber%2=0
Using Views:
CREATE VIEW with_rownumber
as
SELECT ROW_NUMBER() OVER(ORDER BY Employee_id) as RowNumber,* from employees;
SELECT * from with_rownumber where RowNumber%2=0
The approach preferred here is using VIEW because:
1. Easy to understand.
2. In future if you need to perform any operation related to RowNumber
then you don't need to create another complex query. You could use view
having rownumber column in it.
Category:
Database
|
Views:
3461
|
Added by:
Admin
|
Date:
2012-09-03
|
| |
|
|
|