Home > Net >  SQLite table with AS SELECT
SQLite table with AS SELECT

Time:11-26

I have a table called flights which has all information related to flights and I have a table called users.

I want to create a new table called orders, in this table I wanted to add user name from the user table and certain flight information from the flight table.

The thing is I also want to have a column in my order table called orderID.

My question is how do I add a column in a as select query

CodePudding user response:

SELECT *, an_expression AS another_column FROM the_table_or_subquery .... ; 
  • an_expression is that, an enter image description here

    • 2 columns from the flights table new orderID column set to null
    • WARNING see commentary above re column attributes being stripped

    enter image description here

    • the orderId is generated
    • the order_added is generated due to default being CURRENT_TIMESTAMP

    enter image description here

    both the new columns orderid and order_added use expressions that return a random suitable value.

  • Related