简体   繁体   中英

“AS” equivalent in sqlite

I'm a beginner with sqlite coming from mysql. maybe my question is dumb but I can't find the equivalent of the "AS" in mysql for example.

Example: "SELECT firstName || ' ' || lastName AS fullName FROM myTable;"

Is it possible?

Thanks in advance!

SQLite also supports using AS , as shown in this diagram from the page Syntax Diagrams for SQLite :

result-column :

SQLite的语法图

Why do I want to use a "AS"?

Because it allows you to give a descriptive name to each column in your result set. You can use this name to refer to the column when you read the results.

The AS keyword will work just as well in SQLite as it does in mysql. See, for example, the SQLite syntax reference (in particular, the Result Column production ). Your second question: SQLite supports the || concatenation operator .

Note, that you want to use alias name for SELECT ed values anyway, if you intend to reference result columns by name, since the documentation of the sqlite3_column_name function states:

The name of a result column is the value of the "AS" clause for that column, if there is an AS clause. If there is no AS clause then the name of the column is unspecified and may change from one release of SQLite to the next.

SELECT firstName || ' ' || lastName fullName FROM myTable; works for me

UPDATE: not a fond user of sqllite, so did not know AS keyword exists within it. I would not avoid using the keyworkd AS in any statement (as suggested by my answer) as it helps out with code readability a lot.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM