两表关联查询SQL语句的,要怎么写?
1、创建测试表;
create table company(companyId number, companyName varchar2(20), contacts varchar2(20));
create table users(userId number, companyId number, userName varchar2(20), userAge number, address varchar2(20));
2、插入测试数据;
insert into company values (1,'腾讯科技','马化腾');
insert into company values (2,'微软公司','鲍威尔');
insert into company values (3,'新浪科技','小明' );
insert into users values (1,1,'jack',23 , '上海');
insert into users values (2,1,'jack2', 23, '上海');
insert into users values (3,2,'jack3', 23, '上海');
insert into users values (4,2,'jack4', 23, '上海');
insert into users values (5,3,'jack5', 23, '上海');
insert into users values (6,3,'jack6', 23, '上海');
3、查询表中数据;
select * from users;
4、编写sql,关联两张表;select * from users t , company b where t.companyid = b.companyid and t.companyid = 1;
广告 您可能关注的内容 |