-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path6.SUBSTRING.sql
More file actions
40 lines (23 loc) · 854 Bytes
/
6.SUBSTRING.sql
File metadata and controls
40 lines (23 loc) · 854 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
show databases;
-- select substring query
select substring('hello world',1,4);
select substring('Hello world',7);
select substring('hello world',-3);
select substring('hello world',-7);
use book_shop;
select title from books;
select substring("Where I'm Calling From: Selected Stories",1,10); -- when you have single quation in string use "" to avoide error
select substring(title,1,10) from books;
select substring(title,1,10) as short_title from books;
/* Shortcut key SUBSTR() also works
if SUBSTRING is just too much typing for you */
select substr(title,1,10) from books;
select substr(title,1,10) as short_title from books;
-- select concat(short_title, '....') from books; // wrong method
select concat
(substr(title,1,10)
,'...'
)
from books;
select concat
(substr(title,1,10),'...') as short_title from books;