my application reads input table "tbl_names",
do some manipulation with text and put it to the output table "tbl_output". The question is how should I combine two SELECT command together to produce the output. The manipulation with text is not important in this question, the aim is the combining two SELECTs
Code: Select all
table: "tbl_names"
indexes: "id","name","surname"
1,Alexander,Shuterland,
2,Charlotte,Robertson,
3,William,Mackensie,
Shall produce output
Code: Select all
table: "tbl_output"
indexes: "id","name","surname","name_code","surname_code"
1,Alexander,Shuterland,Alex,Shuter,
2,Charlotte,Robertson, Char,Robert,
3,William,Mackensie, Will,Mack ,
Code: Select all
select "id",
case when LOCATE(r, 'Alexander')!=0 then 'Alex'
when LOCATE(r, 'Charlotte')!=0 then 'Char'
when LOCATE(r, 'William')!=0 then 'Will' end
from
(select "id", "name" r from "tbl_names")
# returns
1,Alex,
2,Char,
3,Will,
Code: Select all
select "id",
case when LOCATE(r, 'Shuterland')!=0 then 'Shuter'
when LOCATE(r, 'Robertson')!=0 then 'Robert'
when LOCATE(r, 'Mackensie')!=0 then 'Mack' end
from
(select "id", "surname" r from "tbl_names")
#
returns:
1,Shuter,
2,Robert,
3,Mack ,
Code: Select all
create table "tbl_output"
(
"id" INTEGER,
"name" VARCHAR(20),
"surname" VARCHAR(20),
"name_code" VARCHAR(20),
"surname_code" VARCHAR(20)
)