Xceedas

Xceedas
xceedas

Tuesday, 16 December 2014

[SQL] Get the Values from the Any Combination of a Record from Table


This tutorial about how to get the values from the any combination of a record from table.

data table
1.SQL have the wonderful feature LIKE.
2.LIKE is keyword for following of WHERE condition.
3.LIKE supports %,_ operators.
Lets we look demo,

Like with %

The following query gives the output which are the material_name starts with p. '%' operator supports multi character. so p% means all the values starts with p.

  1. select * from table where material_name like 'p%'  
sql table

Like with _

The following query gives the output for which are the material name starts with 'p' and following 2 characters and end with 't'
  1. select * from table where material_name like 'p__t'(Note: here 2 underscores)   
material table

Another example with % and _


We already discussed with % represents multi character pattern and _ represents one character, use this functionality we can play some thing.

The following query gives, starts with 'p' and multi characters and one space and 3 characters and finally ends with 't'

select * from table where material_name like 'p% ___t'


Sql table of material

I hope this tutorial is useful.

No comments :