SQL - SQLite - 複数テーブルのデータベース設計 - 現行テーブルからの脱却 - 関数、substring_index、substrとinstr
Head First SQL ―頭とからだで覚えるSQLの基本、 Lynn Beighley(著)、 佐藤 直生(監訳)、 松永 多苗子(翻訳)、 オライリージャパンの 7章(複数テーブルのデータベース設計 - 現行テーブルからの脱却)、p.287(自分で考えてみよう)の解答を求めてみる。
入出力結果(Terminal, Zsh)
% sqlite3 gregs_list.db
SQLite version 3.50.0 2025-05-29 14:26:00
Enter ".help" for usage hints.
sqlite> select * from my_contacts ;
アンダーソン|ジリアン|F|jill_anderson@breakneckpizza.com|1980-09-05|テクニカルライター|カリフォルニア州パロアルト|独身|カヤック乗り、爬虫類|恋人、友達|||
sqlite> select substring(interest, 1, instr(interest, '、') - 1) from my_contact
s ;
Parse error: no such column: interest
select substring(interest, 1, instr(interest, '、') - 1) from my_contacts ;
^--- error here
sqlite> select substring(interests, 1, instr(interests, '、') - 1) from my_contacts ;
カヤック乗り
sqlite> select substr(interests, 1, instr(interests, '、') - 1) from my_contacts
;
カヤック乗り
sqlite> select substr(interests, 1, instring(interests, '、') - 1) from my_contacts ;
Parse error: no such function: instring
select substr(interests, 1, instring(interests, '、') - 1) from my_contacts ;
error here ---^
sqlite> select substr(interests, 1, instr(interests, '、') - 1) from my_contacts ;
カヤック乗り
sqlite> .quit
%