Mybatis Dynamic SQL

1. If <select id="findActiveBlogWithTitleLike" resultType="Blog"> SELECT * FROM BLOG WHERE state = ‘ACTIVE’ <if test="title != null"> AND title like #{title} </if> </select> 2. Choose, When, Otherwise <select id="findActiveBlogLike" resultType="Blog"> SELECT * FROM BLOG WHERE state = ‘ACTIVE’ <choose> # choose only one case among many options <when test="title != Read more…

MySQL Strings Segmentation

SUBSTRING_INDEX(str, delim, count) str: the string to be split. delim: the delimiter. count: the position of the delimiter. A positive number means extract from left to right, a negative number means extract from right to left. For example: SELECT SUBSTRING_INDEX('100-200-300-400', '-', 1); — output: '100' SELECT SUBSTRING_INDEX('100-200-300-400', '-', 2); — Read more…

MySQL basic syntax

Database and Table · Create Database CREATE DATABASE <database name>; CREATE DATABASE shop; · Create Table CREATE TABLE <table name> (<column name> <data type> <constrains>, <column name> <data type> <constrains>, …, <constrains of the table>,<constrains of the table>,…); CREATE TABLE product (id CHAR(4) NOT NULL, name VARCHAR(100) NOT NULL, price Read more…

Catalogue