我的第一张表将是包含我希望插入的列状态,目的地,渡轮的港口 我的第二个表是用户名,我希望插入用户名
我如何使用insert语句并在表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);";
谢谢。
答案 0 :(得分:0)
我在Oracle中尝试了这个,它应该可以工作:
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
请注意,您需要一个始终为true的WHERE子句来添加所有可能的条目
答案 1 :(得分:0)
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)