Select last or any position record in sql select statement

Another intresting trick to select last or any position record using sql select stament.
select max(numberField) from TableName
where salary not in (select max(numberField) from TableName);

select *
from TableName testName
where 2 = (select count(*) from TableName b where a.salary <>

Read More!

Check case sensetive string in sql select statement

There is problem while checking case sensetive string in SQL select statement.
We can use a keyword "BINARY" in such case.

Syntax :

select *
from
tableName
where
fieldName = BINARY 'value'
OR

select fieldList
from
tableName
where
fieldName = BINARY 'value'

Where
fieldList : Comma saperated List of fields to select.
tableName : Name of table to select fields form.
fieldName : Field name of which we are checking string.
value : Value to cros check.

Eg :-
If we have a table as
Table Name : EmployeeMaster
Field List :
EmployeeName : varchar (50)
EmployeeCode : varchar (10)

Now we want to select Employees having name exactly 'JON' and case sensetive.

Then SQL select statement will be

select
EmployeeCode,EmployeeName
from
EmployeeMaster
where
EmployeeName = BINARY 'JON'

Note : I have checked this statement in MySql.There might be other way in other RDBMS. Read More!