CREATE TABLE student(id int, name varchar(30), age int, gender char(6));
INSERT INTO student VALUES
(1 ,'Ranga', 27, 'Male'),
(2 ,'Reddy', 26, 'Male'),
(3 ,'Vasu', 50, 'Female'),
(4 ,'Ranga', 27, 'Male'),
(5 ,'Raja', 10, 'Male'),
(6 ,'Pavi', 52, 'Female'),
(7 ,'Vinod', 27, 'Male'),
(8 ,'Vasu', 50, 'Female'),
(9 ,'Ranga', 27, 'Male'),
(10 ,null, 27, 'Male');
Program:
-----------------------------------------------
SELECT * FROM (
SELECT @row := @row +1 AS Rownum, name as Name FROM (SELECT @row :=0) r, student
) students
WHERE rownum %3 = 1;
Output:
-----------------------------------------------
Rownum Name
1 Ranga
4 Ranga
7 Vinod
10 (null)
Sunday, May 17, 2015
Write a SQL Program to Select every Nth record.
Related Posts:
Sorting and Searching the Employee Object by using CollectionIn this post, we can learn how to sort the Employee object by using age and search the Employee object by using age.Employee.java---------------------------------------- package com.ranga;import java.io.Serializable;/** … Read More
Serialization in Java Serialization: Serialization is a process of writing the object state into a file system with extension .ser and recreatign object state from that file(this is called deserialization). Generally objects are stored in th… Read More
What is the output of the following SQL Program. SELECT CASE WHEN null = null THEN 'I LOVE YOU RANGA' ELSE 'I HATE YOU RANGA' end as Message;SELECT CASE WHEN null = null THEN 'I LOVE YOU RANGA' ELSE 'I HATE YOU RANGA' end as Message;Output: 'I HATE YOU RANGA'The reason for this is that the proper way to compare a value to null in SQL is with the is&… Read More
Externalization in JavaIn my previous post ( Serialization), we saw about Serialization. While using Serialization we can get some limitations.Limitations of Serialization: File size is very high because it contains meta information of the file.Cus… Read More
Write a SQL Program to generate the following output?Input:Employee:Department:Output:Creating tables and inserting Data:CREATE TABLE Employee ( e_id INT NOT NULL AUTO_INCREMENT, e_name VARCHAR(100) NOT NULL, age tinyint NOT NULL, PRIMARY KEY (e_id));CREATE TABLE Depart… Read More
0 comments:
Post a Comment