Get 3-letter substrings from the dept column : SUBSTRING « String « SQL / MySQL

Home
SQL / MySQL
1.Aggregate Functions
2.Backup Load
3.Command MySQL
4.Cursor
5.Data Type
6.Database
7.Date Time
8.Engine
9.Event
10.Flow Control
11.FullText Search
12.Function
13.Geometric
14.I18N
15.Insert Delete Update
16.Join
17.Key
18.Math
19.Procedure Function
20.Regular Expression
21.Select Clause
22.String
23.Table Index
24.Transaction
25.Trigger
26.User Permission
27.View
28.Where Clause
29.XML
SQL / MySQL » String » SUBSTRING 
Get 3-letter substrings from the dept column
      
mysql>
mysql> CREATE TABLE IF NOT EXISTS party
    -> (
    ->   id     INT     AUTO_INCREMENT PRIMARY KEY,
    ->   dept CHAR(10), name CHAR(25)
    -> );
Query OK, rows affected (0.00 sec)

mysql>
mysql> # insert records into the "party" table
mysql> INSERT INTO party (dept, name)   VALUES ("accounts""Graham Miller");
Query OK, row affected (0.00 sec)

mysql> INSERT INTO party (dept, name)   VALUES ("sales""Gary Miller");
Query OK, row affected (0.00 sec)

mysql> INSERT INTO party (dept, name)   VALUES ("production""Graham Wallace");
Query OK, row affected (0.00 sec)

mysql>
mysql> # get 3-letter substrings from the dept column
mysql> SELECT SUBSTRING(dept, 13FROM party;
+-----------------------+
| SUBSTRING(dept, 13|
+-----------------------+
| acc                   |
| sal                   |
| pro                   |
+-----------------------+
rows in set (0.00 sec)

mysql>
mysql> # delete this sample table
mysql> DROP TABLE IF EXISTS party;
Query OK, rows affected (0.00 sec)

   
    
    
    
    
    
  
Related examples in the same category
1.SUBSTRING(, )
2.SUBSTRING(, , )
3.Sorting by Variable-Length Substrings
4.Create Initial name with substr function
5.In some cases, pattern matches are equivalent to substring comparisons.
6.SUBSTRING( ) function takes a string and a starting position, returning everything to the right of the positio
7.Substrings can be used to perform comparisons.
8.Sort using combinations of substrings
9.Get the numeric middle part by beginning with the ID, then stripping off the rightmost suffix
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.