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
How to rename or change table name in SQL?
SQL >> rename table_name1 to new_table_name;
alter table table_name_old rename to table_name_new;
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);
Get numeric values only using SQL ?
I have table with one column. Type varchar.. phone --------------- 99samn44423m44 8034skdf3453a2 909090abc4567d i want to get numeric values.. I mean my output will be phone --------------- 994442344 80343453a2 9090904567 thanks in advance.. sateesh
Code
SELECT REPLACE(TRANSLATE(LOWER(99sAmn44423mz44),abcdefghijklmnopqrstuvwxyz, ), ,) FROM dual
Code
SELECT columnname FROM tablename WHERE regexp_like(columnname,^[[:digit:]]+$) ;
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...
State true or false. !=, <>, ^= all denote the same operation.
True
In SQL 2005 only != and <> operator perform same operation
^= does not work
^= operator is a Bit wise Exclusive OR operater in MS SQL.
It stands into category of compound operators and performs a bitwise exclusive OR and sets the original value to the result.
Difference between varchar and varchar2?
Answered by: muralidhar_batta
Member Since Feb-2006 | Answered On : Feb 26th, 2006
varchar means fixed length character data(size) ie., min size-1 and max-2000
where as varchar2 means variable length character data ie., min-1 to max-4000
Varchar - If we declare datatype as varchar then it will occupy space for null values. It can store upto 2000 bytes of character.
Varchar2 - If we declare datatype as varchar2, it will not occupy any space. It can store 4000 bytes of character.
Thanx,
Difference b/w varchar and varchar2 is varchar is ANSI standard and varchar2 is a Oracle data type
and also varchar is fixed length record, varchar2 is variable length.
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...
What is difference between DBMS and RDBMS?
SQL is command line argument. You can access data into database to write procedure.
what are the 12 rules of CODD
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
What are steps to follow for query tuning ?
What is the difference between SQL and SQL server?
Not known
ORACLE organises the database of collection data and this data retrieve from sql .So sql is a language but sql-server is a product of Microsoft which support sql.
SQL is a language which is used to retrieve and manipulate data in database .... SQL Server is the relational data base management system, a product from Microsoft.
Editorial / Best Answer
Answered 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: