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 13040

How can analyze query after generating explain plan ?

Thermotech,

2 7113

What is rule base and cost base optimizer?

Thermotech,

2 7379

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

HCL,

4 15610

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

1767

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 5769

what is julian date in oracle

2 8575

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

Thermotech,

3 16828

What is Highwatermark?

Thermotech,

3 10787

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

iGate,

29 25465

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

2 7089

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 10393

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

Satyam,

9 13189

Do view contain data?

Ramco,

6 9300


Post New SQL PLSQL Questions

Un-Answered Questions { SQL PLSQL }

What are the types of functions in sql?

558


What are the different tcl commands in sql?

616


What is pl sql block in dbms?

524


What are triggers and its uses?

589


What are database links used for?

591






Does execute immediate commit?

691


Why should I use postgresql?

557


How can you load multi line records? : aql loader

652


What is nested table in pl sql?

547


how to select unique records from a table? : Sql dba

622


What are the advantages of stored procedure?

535


how do you know if your mysql server is alive? : Sql dba

592


What does count (*) do in sql?

516


What is difference between primary and secondary key?

515


What is trigger and types?

555