SIGN UP MEMBER LOGIN:    
ARTICLE

MySQL Operators And Comparison Functions

Posted by Arjun Panwar Articles | Databases & DBA January 12, 2012
Here we will show how to work with the Operators and Comparison Functions in MySQL
Reader Level:

Use GREATEST(value1,value2,...) function with column data

Here first of all we have to create a table "employees" and after that insert values into the table. Find the greatest values of  the column in the table.

mysql> CREATE TABLE Employees(
>id        int,
>first_name    VARCHAR(15),
>last_name     VARCHAR(15),
>start_date    DATE,
>end_date      DATE,
>salary        FLOAT(8,2),
>description   VARCHAR(15)
>);

mysql>insert into Employees(id,first_name, last_name, start_date, end_Date,   salary, Description)
> values (1,'Akshay',    'Martin',  '19960725',  '20060725', 1234.56,  'Programmer');

mysql>insert into Employees(id,first_name, last_name, start_date, end_Date,   salary, Description)
 >values(2,'Akash',   'Mathews',  '19760321', '19860221', 6661.78, 'Tester');

mysql>insert into Employees(id,first_name, last_name, start_date, end_Date,   salary, Description)
> values(3,'Amit',    'Smith',    '19781212', '19900315', 6544.78, 'Tester');

mysql>insert into Employees(id,first_name, last_name, start_date, end_Date,   salary, Description)
>values(4,'Deepak',    'Rice',     '19821024', '19990421', 2344.78,'Manager');

mysql> insert into Employees(id,first_name, last_name, start_date, end_Date,   salary, Description)
>values(5,'Manoj',   'Black',    '19840115', '19980808', 2334.78,'Tester');

mysql> insert into Employees(id,first_name, last_name, start_date, end_Date,   salary, Description)
 > values(6,'manish',    'Green',    '19870730', '19960104', 4322.78, 'Tester');

mysql> insert into Employees(id,first_name, last_name, start_date, end_Date,   salary, Description)
> values(7,'David',    'Larry',    '19901231', '19980212', 7897.78, 'Manager');

mysql> insert into Employees(id,first_name, last_name, start_date, end_Date,   salary, Description)
> values(8,'Rohtash',    'Cat',     '19960917',  '20020415', 1232.78,'Tester');

mysql> select * from  employees;

img 1.gif

Syntax

mysql> select GREATEST(salary, 5000) from employee;

img 1.1.gif

GREATEST(@id1, @id2, @id3, @id4, @id5): using Greatest function with user-defined variables.

Syntax

mysql>   SELECT *
        >    FROM employees
       >     WHERE ID=GREATEST(@id1, @id2, @id3, @id4, @id5);

img 2.gif


mysql> SELECT GREATEST(3.0,3.0,5.0,7.0);

img 3.gif


GREATEST(value1,value2,...) returns NULL if any argument is NULL.

Syntax
mysql> SELECT GREATEST(2,NULL);

img 4.gif

GREATEST(value1,value2,...) returns the largest (maximum-valued) argument within two or more arguments.

Syntax
mysql> SELECT GREATEST(2,0);

img 5.gif


SELECT GREATEST('B','A','C');

Synatax
mysql> SELECT GREATEST('B','A','C');

img 6.gif

Resources

Here are some useful resources:

Login to add your contents and source code to this article
share this article :
post comment
 
Nevron Gauge for SharePoint
Become a Sponsor
PREMIUM SPONSORS
  • ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications. Visit DynamicPDF here
    Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
6 Months Free & No Setup Fees ASP.NET Hosting!
Become a Sponsor