i have a table student like
sname
-----
ram
ram
ram
raj
raj
raj
i need the output like
sname
-----
ram
raj
ram
raj
ram
raj
Answer Posted / praveend
This query ill run on MySQL
CREATE TABLE IF NOT EXISTS `stu` (
`id` int(5) DEFAULT NULL,
`sname` varchar(20) DEFAULT NULL
)
INSERT INTO `stu` (`id`, `sname`) VALUES
(1, 'ram'),
(2, 'ram'),
(3, 'ram'),
(4, 'raj'),
(5, 'raj'),
(6, 'raj');
ANSWER
select sname from (
select (id- round((select count(*)from stu)/2)) as id, sname from stu where id >((select count(*)from stu)/2)
UNION
select * from stu where id<4
) as B order by(id)
| Is This Answer Correct ? | 0 Yes | 0 No |
Post New Answer View All Answers
What are the main differences between #temp tables and @table variables and which one is preferred?
Tell me what is use of except clause? How it differs from not in clause?
How do you use a subquery to find records that exist in one table and do not exist in another?
Do you know how to store and query spatial data?
can a table be moved to different filegroup? : Sql server administration
What are a scheduled jobs or what is a scheduled tasks?
As a general practice, it is recommended to have dbo be the owner of all database objects however, in your database you find number of tables owned by a user other than dbo, how could you fix this?
your sql server is running out of disk space. You notice that there are several large files with ldf extensions what are these files? : Sql server administration
What is the usage of the sign function?
How to assign new column names in a view?
List out the differences between the clustered index and non-clustered index in sql server?
What is a collation in ms sql server?
How to divide query output into multiple groups with the group by clause in ms sql server?
What is the impact on other user sessions when creating indexes?
What are the steps to take to improve performance of a poor performing query? : sql server database administration