Topics Search

Query to find the second highest column value in a table

Query to find the second highest column value in a table
Views: 452
In this ms sql server tutorial you will learn query to find the second highest column value in a table.
Sponsored Links:

More topics

 

4 Ways to find Nth highest salary in SQL

Preview
One of the most common SQL interview questions is to find the Nth highest salary of employee, where N could be 2, 3, 4 or anything e.g. find the second highest salary in SQL. Sometimes this question is also twisted as to find the nth minimum salary in SQL. Since many Programmers only know the easy way to solve this problem e.g. by using SQL IN clause, which doesn't scale well, they struggle to write the SQL query when Interviewer keep asking about 4th highest, 5th highest and so on.
 

Second Highest Salary in MySQL and SQL Server

Preview
Write a SQL query to get the second highest salary from the Employee table. For example, given the above Employee table, the second highest salary is 200. If there is no second highest salary, then the query should return NULL. You can write SQL query in any of your favorite database e.g. MySQL, Microsoft SQL Server or Oracle.
 

Query to find the second lowest column value in a table

Preview
In this ms sql server tutorial you will learn query to find the second lowest column value in a table.
 

Select the Nth Highest Record in a Database Table

Preview
In this tutorial, you will learn how to select the Nth highest record in a database table by using various techniques. These techniques are very useful, for instance you may want to see the product which is second most expensive in Products database table.
 

Changing Column Size

Preview
Changing the size of a column in MySQL is pretty easy. By using alter table and modify you are able to choose a column on a specified table and resize it. Learn how to resize a MySQL column.
 

How to Change a Column Name

Preview
If you have created a database and decide later that one of the column names you chose isn't exactly what you want, you can rename it. You do this using alter table and change. Together they can be used to rename a MySQL column.
 

Changing Table Structure Using MySQL ALTER TABLE

Preview
Changing existing table structure is a very important task especially when the current table structure no longer reflects the new business's needs. In this tutorial, you will learn about MySQL ALTER TABLE statement to change existing table structure such as add or drop column, change column attribute and rename table.
 

Using the aggregate functions ANY, SOME, EVERY

Preview
If you have used SQL a bit, you are certainly familiar with so-called set functions or aggregate functions COUNT, SUM, AVG, described in the manual. For example, let’s say that I am the owner of a shop and I keep track of daily sales in this table: create table sales (month int, day int, amount int); The first column is the number of the month, between 1 and 12, the second column is the number of the day in the month, between 1 and 31, and the third column is how much we sold on that date.
 

MySQL Datatypes

Preview
Once you have your table data organized, the next step is to figure out the data type. There are three main types : text, numbers, and Dates/Times. Choosing the column types specifies what information can or can't be stored in a table cell. Using the most correct option for each column is important as it may affect the database's overall performance.
 

Order a string column as an integer

Preview
If you order a string column that contains only numeric values with MySQL, it will order them as string values, e.g.: 1, 10, 100, 2, 3, 31, 32, 4, etc. If you want to order them as if they were an integer, cast them in the order by clause.
Normally you'd store numeric values in a numeric column in the database, but sometimes this isn't possible. For example, the postmeta table in WordPress has a meta_value column which is a string and in which you might store only numeric values for a particular meta_key field.