SQL / MySQL examples (example source code) Organized by topic





Procedure Function /

Begin End 1BIGINT 2Buildin Functions 6Call 6
CASE 5CHAR 1Condition HANDLER 10Create Table 3
CSharp 2DATE 3DATETIME 1Default 2
DEFINER 1Delete 2Delimiter 1DETERMINISTIC 1
DOUBLE 1Drop Table 1Dynamic Statement 2FLOAT 2
Function Data Dictionary 3Function Returning 7Function 10IF statement 5
Insert 4INT 1Introduction 8ITERATE 1
Java 2LEAVE 3Lock 1LOOP 6
NUMERIC 2Operator 2Output 3Parameters 15
Perl 2PHP 2Predefined Exceptions 3Procedure Data Dictionary 5
Procedure 14Python 1Recursion 1Repeat until 4
Select Into 3Set 4TEXT 2Transaction 7
Update Table 2VARCHAR 2Variable Assignment 3Variable Declaration 3
Variable Scope 5VB.net 1While 4

Trigger /

After Trigger 3Before Trigger 7Drop Trigger 1NEW 4
Trigger Data Dictionary 1

View /

Alter View 2Check 3Create View 17Drop View 1
Explain View 1Nested View 1Updatable View 1View Structure 2

Cursor /

Close 1Declare 3Fetch 8Handler 1
Open 1

Select Clause /

Alias 7All 8Any 7Count 14
Distinct 16Exists 7Function In Select 1Group 45
HAVING 7In 14Like 11Limits 27
Operator 14ROLLUP 4Row 6Select 13
Simple Select 13Sort Order 69Sub query 68Union 31
Unique 3Using 2Variable 50

Where Clause /

And 12OR 6Where 30

Insert Delete Update /

Delete 14Insert 24Update 25

Flow Control /

CASE WHEN Select 6Flow Control Select 1IF 2

Data Type /

AUTO_INCREMENT 19BigInt 1Bit 1Blob 3
Boolean 3Char 13Data Type Convert 1Data Type Summary 5
Date 10DateTime 5Decimal 9Double 2
ENUM 30Float 5FullText 1Int 7
Integer Type 9LongBlob 1LongText 1MediumBlob 1
MediumInt 1MediumText 1Null 22Serial 1
Set 6Small Int 7Text Type 3Time 3
TimeStamp 13Tiny Int 4TinyBlob 1TinyText 1
Varchar 7Year 1

Date Time /

ADDDATE 7ADDTIME 3CURDATE 4CURTIME 2
Date Compare Order 6Date Format 29Date Function 11Date Time Function 1
Date Type 13DATE 7DATEDIFF 2DATETIME 3
DATE_ADD 9DATE_FORMAT 2DATE_SUB 6Day 3
DAYNAME 8DAYOFMONTH 2DAYOFWEEK 5DAYOFYEAR 3
EXTRACT 1FROM_DAYS 2FROM_UNIXTIME 3GET_FORMAT 1
HOUR 2INTERVAL 14MINUTE 1Month 10
MONTHNAME 2NOW 2SECOND 2SEC_TO_TIME 4
SUBDATE 2Time zone 6Time 8TIMEDIFF 2
TIMESTAMP 7TIMESTAMPADD 1TIMESTAMPDIFF 1TIME_FORMAT 3
TIME_TO_SEC 9TO_DAYS 6UNIX_TIMESTAMP 5UTC_TIMESTAMP 1
WEEKDAY 2Year 38

String /

ASCII 3Binary 11CHAR_LENGTH 2COLLATION 1
CONCAT 12CONCAT_WS 3CONVERT 3Escape 2
INSTR 1LEFT 4LENGTH 9LOCATE 4
LOWER 2Mid 2ORD 1REPEAT 2
REPLACE 2REVERSE 1RIGHT 4Row 3
RPAD 1SOUNDEX 1STRCMP 2String Append 6
String Case Function 1String Compare 8String Function 2String Length 1
String Type 3Sub String 2SUBSTRING 10SUBSTRING_INDEX 3
Trim 3UPPER 1

Math /

ABS 2ACOS 1ASIN 1ATAN 2
Average 4CEIL 1COS 1COT 3
Degree 1Exp 1Floor Ceiling 2FLOOR 5
GREATEST 1LEAST 1LOG 2LPAD 1
Max Min 1Max 3MID 1Min 1
MOD 5PI 2PLUS 1Power 3
RADIANS 1Random 1Round 3SIN 2
SQRT 2Sum 8TAN 1TRUNCATE 2

Function /

AND 2Between 7BIN 2BINARY 1
BIT Count 1Bit 13BIT_AND 1BIT_OR 1
BIT_XOR 2CASE 21CAST 8COALESCE 3
COERCIBILITY 1Compare Function 1CONNECTION_ID 1CONV 2
COT 1DECODE 1Define Function 4EXTRACT 1
FIELD 1FOUND_ROWS 2Function In Join 2Function In Select 2
IF 6IFNULL 7IN 4INET_ATON 3
INSTR 1ISNULL 1LAST_INSERT_ID 6MD5 4
MySQL Version 1NULLIF 1OR 2RAND 12
Replace 7Right 1SHA 1SIGN 1
XOR 2

Aggregate Functions /

AVG 8COUNT 31GROUP_CONCAT 3MAX 10
MIN 9STD 1STDDEV 1STDDEV_SAMP 1
SUM 11VARIANCE 1VAR_SAMP 1

Geometric /

AREA 3ASTEXT 3Bounding Box 1Distance 2
ENDPOINT 1ENVELOPE 1Geometric Functions 2Geometric Objects 1
Geometric Types 2GeometryCollection 2GEOMFROMTEXT 3Index 2
Length 3Line 1MULTIPOINT 1Point 3
polygon 4TOUCHES 1X 1Y 1

XML /

Descendant 1Element 8EXTRACTVALUE 13Update 1
UPDATEXML 1XPath 1

Regular Expression /

Begin With 10Class 1Contains 10End With 5
Introduction 23Like 17Patterns 10Percentage wildcard 4
REGEXP 21Underscore 1

I18N /

CHARSET 21Collate 22utf8 5

FullText Search /

Boolean Search 9Index 6MATCH 16Natural Language 3
Operator 3Word 15

Database /

Create Database 2Current Database 3

Event /

Alter 1Create 10Drop 1Enable 1
Rename 1Schedule 6

Backup Load /

Backup 1Batch 1Dump 1Export 3
Load Data Into Table 13Load Text File 2Save To Text File 18

Command MySQL /

ANALYZE 1BACKUP 2Cancel 1CHECK 2
CHECKSUM 1Clear 1Comment 3Connect MySQL 1
Database 1DEALLOCATE 1DESCRIBE 3Drop 2
Exit MySQL 1EXPLAIN 3Global Variables 10INFORMATION_SCHEMA 9
LOAD 15Lock 1Matadata 8my.cnf 3
MySQL 43Mysqladmin 10mysqldump 26mysqlhotcopy 1
mysqlimport 5OPTIMIZE 3PREPARE 3RENAME 7
Repair 2RESTORE 1Set 1Show 41
SOURCE 1Status 1Version 3

User Permission /

Add User 5Drop User 3Grant 53Password 33
Permission 3Privilege 1Rename User 1REVOKE 7
SQL Privilege 11User Create 2User Table 8USER 10

Table Index /

Alter Table 44Backup Table 6Check 3Column 77
Constraint 4Copy Table 17Create Table 32Current Table 1
Default Value 5Delete Table 3Drop Table 5Index 39
Rename Table 1Table Structure 1Temporary Table 9TRUNCATE 3

Join /

Condition JOIN 1Cross Join 1Database Join 4Delete From Join 3
Full Join 3Function In Join 2Inner Join 10Join Delete 3
Join Order 3Join Select 39Join Table 7Join Three Tables 2
Join Update 2Left Join 22Right Join 5Self Join 4
Simple JOIN 20Using 9

Transaction /

autocommit 4COMMIT 2ISOLATION 2Lock 5
RollBack 4Savepoint 2TRANSACTION COMMIT 2TRANSACTION ROLLBACK 3

Key /

Foreign Key 9Key 1Primary Key 19

Engine /

Change 2CSV 1Engine Type 3InnoDB 1
Merge 1MyISAM 6