How do you print the last n rows or the first n rows of a table ?
Find second lowest salary from emp table
Display the second lowest salary from emp table without using min & all
Ypu need to know MR. SQL that you cant use = operator with rownum ....
Code
SELECT * FROM emp a WHERE (&n-1) =(SELECT count(UNIQUE sal) FROM emp b WHERE a.sal>b.sal) FOR nth minimum salary SELECT * FROM emp a WHERE (&n-1) =(SELECT count(UNIQUE sal) FROM emp b WHERE a.sal<b.sal) FOR nth maximum salary
Query to find the list of employees age > 30
Write a query to find the list of employees whos age is greater than 30 or so given a date of birth column
Please tell me,
How to get age of all employee by using query
SELECT *,DATEDIFF(YY,
Thanks & Regards
K.santhosh
Deleting duplicate records in a table without using rowid
1. How to delete a duplicate records in a table without using rowid? 2. What is the use of connect by clause? 3. What is the use of connect by clause? 4. How to display "experience of employee"?E.G. 3 years 4 months 19 days? 5. What is select statement to spe?
We delete the duplicate records using level and rownum. The query is
Code
DELETE FROM emp WHERE ROWNUM IN(SELECT MAX(ROWNUM) FROM emp WHERE LEVEL=nth CONNECT BY PRIOR empno>empno GROUP BY LEVEL);
1 Delete from table_name where ROWID not in ( selectmax(rowid) from table group by duplicate_values_field_name);
Hi, i have 3 files each having 2 cols e.G file1 empid deptid 1 100 2 200 3 200 4 100 5 300 file2 empid salary 1 10 2 20 3 30 4 40 5 ...
I believe what you are looking for is a query like this:
select f3.deptname dept_name, sum(isnull(f2.salary,0)) amt_spent_each_dept
from file3 f3 left join file1 f1 on (f3.deptid = f1.deptid)
left join file2 f2 on (f1.empid = f2.empid)
group by f3.deptname
order by f3.deptname
What is the advantage in creating force view?
Force view creates the view even if the underlying tables / referenced objects are not present. Force View are used while executing a script that has create tables and views statements or while creating a view for remote table.
What is the advantage to use trigger in your pl?
1.Auditing the tables
2.Online transaction
3.Securing from another table
4.Automatic calculations
5.Replicate the tables
The main advantages of the triggers are
* To Audit the table
* To check the complex conditions which are not possible by the constraints.
Explain normalization with examples?
Normalization--To Reduce or to remove the redundancy in table we used Normalization and the normalization we can achieve by breaking of tables by this table is in Normalized.
0NF "sql CUSTOMER ORDER (CustName, OrderNo, ProdNo, ProdDesc, Qty, CustAddress, DateOrdered) 1NF - remove multivalued attributes "sql CUSTO...
What is a sub query and co-related sub query?
Sub query: A sub query is executed once for the parent statement. Correlated Sub query: Correlated sub query runs once for each row selected by the outer query. It contains a reference to a value fr...
How to get number of days using SQL ?
I have table .. Like empno ename dob ------------------------------------ 1 you 1-jan-2011 2 me 28-jan-2011 tel me the query for no.Of days different from.. Two dates of column dob.? thanks in advance. sateesh
select date1-date2 from tablename;
If the above value is negative it means date 1 is older than date 2
How to insert a column in middle order?
Hi,i have 1 table contain 2 column if I add a new column it default stored in last column but my recruitment adding the new column in middle of the order so can any one explain
Mr. Chandu can you give some example code. I am not clear with the code you have posted.
You can use BEFORE < col name >
or
AFTER < col name >
or
< col name > 2
Here 2 is the position that the new col is about to place.
How to retrieve the 2nd record from a table ?
How to retrieve the 2nd record from a table which has say 1000 records in it. Please answer this without using the row-id? I tried to say a query "select * from table where rowcount=1" which worked well and also "select * from table where rowcount=3" which gave me the result but not when I did the same...
Code
SELECT * FROM `table_name` WHERE rownum <> 1 ORDER BY rownum ASC LIMIT 1;
the best way to issue is
select top 1 * from cars where id_car in
(select top 2 id_car from cars order by id_car)
order by id_car DESC
and with that
obtain the second record (This way is for the PK)
Retrieve all columns except 1 in a table.
I have a table with 20 columns and I have to retrieve 19 except one. is there any way easier then giving select col1,col2,col3,..........Col19 from table1.
if we are dong select top 33* from table, we will get topmost 33 records but not the all 33 columns except 1 column in a table.
select top 19 * from table1
How to delete identical row from a table?
How to delete identical row from a table? if we have 4 row and two of them having same data then how we delete identical row using delete query
its not clear...... it will be execute correctly?
delete from table_name where rowid not in (SELECT max(rowid) FROM table_name group by (column_name))
What is difference between co-related sub query and nested sub query?
Co-related sub query is one in which inner query is evaluated only once and from that result outer query is evaluated.Nested query is one in which inner query is evaluated for multiple times for gatting one row of that outer query.Ex. Query used with in() clause is co-related query. Query used with...
If the evaluation of an inner query(a sub query) depends on a variable which gets its value in an outer query,such a subquery has to be evaluated for each value of the variable.Such a query is a corre...
If the evaluation of an inner querry(a sub querry) depends on a variable which gets its value in an outer querry,such a subquerry has to be evaluated for each value of the variable.Such a querry is a ...
How many tables are needed to create and their relationships ?
Supplier name supplier site supplier street supplier contact person supplier city supplier state supplier phone number business requirement is : one supplier can have multiple ( n number of sites ), one supplier site can have multiple contacts persons ( n number of contact persons ), one supplier contact...
Supplier Table Columns : Supplier id , supplier name (Supplier ID, supplier name as Primary Key) Supplier Site Details Columns : Supplier name , site, street, city, state (Supplier name as foreign Ke...
What is the difference between inner join and outer join?
First to define what Inner Join and Outer Join mean. Inner Join: A join between two tables were only those records in both tables that meet the conditions of the join expression are returned. In most...
Is it possible to create user without using (create user) command ?
If you want is not created a user with command line, you should create it with the interface
Use Grant command to create user and giving permission.
Suppose im having employee table with fields, eno, ename, dept, address1, address2, address3. In address field employee can fill only address1 or address2 or address3... At a time he can fill three address fields. Now I want all employee names who filled only one address field..
Given a select statement that has a group by clause.The having clause uses the same syntax as which other clause?A. Whereb. Unionc. Subqueryd. Order by
It's like WHERE clause but "HAVING" It is more commun to use with GROUP BY
Having clause is used filter data which is retrieve by group by clause.for example: if you try to use having to filter data instead of where clause then it fires error.the style of query is:- 1...
Editorial / Best Answer
Answered by: nirmal1in
View all questions by nirmal1in View all answers by nirmal1in
Member Since Jan-2010 | Answered On : Jan 16th, 2010
This can be accomplished in following way:
Example: table - emp
For First n rows:
SELECT * FROM
(SELECT empno,ename,job,row_number() over (order by ename desc) a
FROM emp) x
WHERE x.a < 5 --- say n is 5 display first 5 records
For last n rows:
SELECT * FROM
FROM )WHERE .a<(SELECT empno,ename,job,row_number() over (order by ename) a
FROM emp) x
WHERE x.a < 5
This query can be used for finding nth row also say n = 5
SELECT * FROM
(SELECT empno,ename,job,row_number() over (order by ename desc) a
FROM emp) x
WHERE x.a = 5
For First N Rows: