开发者

How do i insert data into 1 table from 2 other tables?

My 1st table would be port which has columns status,destination,ferry that i wish to insert My 2nd table would be users which 开发者_如何学编程has columns Username that i wish to insert

How would i use insert statement and insert all these columns in table Booking?

   private static final String DATABASE_CREATE =
        "create table user (_id integer primary key autoincrement, "
        + "Username text not null, Password text not null,"
        + "LastName text not null, FirstName text not null);";

    private static final String DATABASE_CREATE_2 =
        "create table port (_id integer primary key autoincrement, "
        + "status text null, destination text null,"
        + "arrival text null, ferry text null);";

    private static final String DATABASE_CREATE_3 =
        "create table booking (_id integer primary key autoincrement, "
        + "ArrivalTime text null, Destination text null,"
        + "user text null, ferry text null);";

Thank you.


I tried this in Oracle and it should work:

INSERT INTO booking (ArrivalTime, Destination, user, ferry) 
SELECT port.arrival, port.destination, user.Username, port.ferry 
FROM port, user WHERE port._id Is Not Null 

Note that you need a WHERE clause that is always true to add all the possible entries


sql server 2008:-

insert into booking 
select p.arravialtime,p.destination,u.username,p.ferry
from port p
(most sutaible join according to your requirenment)
 user u
  where (your condition)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜