SQL PLSQL Interview Questions
Questions Answers Views Company eMail


Hi, Can anybody please explain me the flow of the below query. I am not able to understand how this query works. This query is for finding the Nth highest salary.. SELECT DISTINCT (a.sal) FROM EMP A WHERE &N = (SELECT COUNT (DISTINCT (b.sal)) FROM EMP B WHERE a.sal<=b.sal); If N = 2 then second highest salary will be the o/p. If N = 3 then third highest salary will be the o/p. and so on.. Thanks, Nitin

Deloitte, Ness Technologies,

5 13076

How can analyze query after generating explain plan ?

Thermotech,

2 7130

What is rule base and cost base optimizer?

Thermotech,

2 7399

Write one update command to update seqno field of a table on the basis of row number.

HCL,

4 15646

Hi, I am new in oracle(SQL), could anyone help me in writing a correct SQL. Below is the table structure. Table: Subsc Fields: 1. Sub_no (this field will hold values of subscriber nos, for e.g. S111111, S222222, S333333, S444444, etc.) 2. s_status (this field will hold values for different status of subscriber, for e.g. 'A', 'S', 'C', etc.) 3. cus_id (this field will hold values of bill nos for e.g. 11111111, 22222222, 33333333, 44444444, etc.) Table: Bill Fields: 1. Bill_no this field will hold values of bill nos for e.g. 11111111, 22222222, 33333333, 44444444, etc.) 2. b_status = (this field will hold values for different status of bill for e.g. 'O', 'C', 'S', etc.) Note: 1. The Sub_no is a Primary key of Subsc table. 2. The cus_id is a foreign in Subsc table (referred from Bill_no field of Bill table) 3. The Bill_no field is the Primary key of Bill table. Query A --> I wrote a query to select cus_id/Bill_no which is in status open (b_status = 'O') and having more than two active subscriber (i.e. S_status = 'A') in it ( i.e. more the two subscribers in same bill). select s.cus_id from subsc s where exists (select 1 from bill where bill_no = s.cus_id and b_status = 'O') and s_status = 'A' group by s.cus_id having count(sub_no) = 2 Problem : The above query will give the cus_id (or rather bill_no) which are in open status (b_status ='O) and which are having TWO ACTIVE Subscribers (s_status ='A') in it. However, this query will also lists the cus_id/bill_no which are having more than TWO subscribers in it (but only two subscriber will be in Active status (s_status = 'A') and the others will be in s_status = 'C' or s_status = 'S'. Help needed: I want to write a query which will fetch ONLY the cus_id/bill_no which are in open status (b_status ='O') and which are having ONLY TWO ACTIVE subscribers (s_status ='A') in it. B--> If I include the sub_no in the above query then NO row are returned. select s.cus_id, s.sub_no from subsc s where exists (select 1 from bill where bill_no = s.cus_id and b_status = 'O') and s_status = 'A' group by s.cus_id, s.sub_no having count(sub_no) = 2 Help needed: I want to modify the above query which will fetch ONLY the cus_id/bill_no which are in open status (b_status ='O') and which are having ONLY TWO ACTIVE subscribers (s_status ='A') in it ALONG with the sub_no. Thanks a lot in advance. Regards, Nitin

1774

Let us suppose we have a table with structure in order empno empname empdesig empcountry and now i want to re-organize the columns of this table to empno empdesig empname empcountry how can i do this with queries ? assume that table contains the data.

3 5809

what is julian date in oracle

2 8606

I want to know the difference between A Record Type and a Table.

Thermotech,

3 16865

What is Highwatermark?

Thermotech,

3 10827

how to get second highest salary in SQL(as/4000

iGate,

29 25616

write a query to display diference between two dates in sql server

2 7104

mail-id table contains two columns(email_id,userid) it contains different types of mail-ids,and no of users. here username length is differ na,(ex- tamil@yahoo.com,joshua@hotmail.com like) now i want to fetch the email-ids only starting from '@' (ex-@gmail.com,@yahoo.com,@hotmail.com

5 10425

oracle is compiler or interpretter,can any one tell me the answer?

Satyam,

9 13258

Do view contain data?

Ramco,

6 9349


Post New SQL PLSQL Questions

Un-Answered Questions { SQL PLSQL }

what are the different tables present in mysql? : Sql dba

506


what are the t string functions available in tsql? : Transact sql

545


Are left and right joins the same?

536


Is nosql faster than sql?

544


What does select top 1 do in sql?

544






Can I create table without primary key?

533


How do I find duplicates in two columns?

557


What is the main difference between sql and pl/sql?

569


How many types of sql are there?

531


Does access use sql?

565


What is record data type?

518


Suppose a student column has two columns, name and marks. How to get name and marks of the top three students.

532


What is the difference between unique and primary key constraints?

588


what is single byte over head in oracle..?

1873


What are tables and fields in the database?

556