write a query for list of owner who are having multiple
bikes in below table
1 shanker pulsar
2 shanker Honda
3 shanker car
4 Balu pulsar
5 Balu Honda
6 Balu car
7 Shyam pulsar
8 Jaya Honda
9 Deepa car
10 vasu car

Answer Posted / lakshmi narayanan r

CREATE TABLE bikes (bikeID INT, CName VARCHAR(50), BNAME
VARCHAR(50))

INSERT INTO bikes(CName, BNAME) VALUES ('shanker', 'pulsar')
INSERT INTO bikes(CName, BNAME) VALUES ('shanker', 'Honda')
INSERT INTO bikes(CName, BNAME) VALUES ('shanker', 'car')
INSERT INTO bikes(CName, BNAME) VALUES ('Balu', 'pulsar')
INSERT INTO bikes(CName, BNAME) VALUES ('Balu', 'Honda')
INSERT INTO bikes(CName, BNAME) VALUES ('Balu', 'car')
INSERT INTO bikes(CName, BNAME) VALUES ('Shyam', 'pulsar')
INSERT INTO bikes(CName, BNAME) VALUES ('Jaya', 'Honda')
INSERT INTO bikes(CName, BNAME) VALUES ('Deepa', 'car')
INSERT INTO bikes(CName, BNAME) VALUES ('vasu', 'car')


;WITH tmp (RowId, CName) AS (SELECT ROW_NUMBER() OVER
(PARTITION BY CName ORDER BY BikeID ASC) AS RowId, CName
FROM Bikes)
SELECT DISTINCT CName FROM tmp WHERE RowId > 1

Is This Answer Correct ?    1 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is the difference between varchar and nvarchar datatypes?

569


How many categories of functions based their return modes?

585


How do you make a trace?

578


What is a full text index?

490


How to add additional conditions in SQL?

582






what are the steps you will take, if you are tasked with securing an sql server? : Sql server database administration

551


How would you go about developing a ssrs report?

110


Write a sql query to display the current date?

626


Write SQL queries on Self Join and Inner Join.

605


Differentiate between truncate vs delete in mssql?

521


What are the basic functions for master, msdb, model, tempdb and resource databases?

547


What is the difference between ‘having’ clause and a ‘where’ clause?

543


How many instances per computer are there in sql server 2000?

576


What is history table in sql server?

499


What is the use of =,==,=== operators?

568