Search code examples
androidsqliteandroid-sqlitestring-concatenationcreate-view

Merging Two Strings while building view in sqlite


I am trying to build sqlite view vwCOMPLETE_INFO from 2 tables (CUSTOMERS and CITIES)

but i have problem in merging the FIRST_NAME and LAST_NAME to build FULL_NAME Column in the new view

CREATE VIEW vwCOMPLETE_INFO AS SELECT (CUSTOMERS.FIRST_NAME || CUSTOMERS.LAST_NAME AS FULL_NAME), CUSTOMERS.AGE, CITIES.NAME FROM CITIES JOIN CUSTOMERS ON CUSTOMER.CITY_ID = CITY.ID;

what could fix that ?


Solution

  • The issue is that you are including AS FULL_NAME as part of the term that builds the column's data, rather than where it should be as after the term so that it names the column accordingly.

    In short AS FULL_NAME should be the other-side of/outside/after the parenthesis's. i.e. ....CUSTOMERS.LAST_NAME) AS FULL_NAME..... rather than .....CUSTOMERS.LAST_NAME AS FULL_NAME).....

    Try

    CREATE VIEW vwCOMPLETE_INFO AS SELECT (CUSTOMERS.FIRST_NAME || CUSTOMERS.LAST_NAME) AS FULL_NAME, CUSTOMERS.AGE, CITIES.NAME FROM CITIES JOIN CUSTOMERS ON CUSTOMER.CITY_ID = CITY.ID;