[英]How do i insert data into 1 table from 2 other tables?
我的第一张表将是我要插入的具有状态栏,目的地,渡轮的端口。我的第二张表将是我要插入的具有用户名栏的用户。
我将如何使用插入语句并将所有这些列插入预订表中?
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);";
谢谢。
我在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子句以添加所有可能的条目
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)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.