---------------------------------------------------------------- -- Author :DBA_HuangZJ(發糞塗牆) -- Date :2014-07-08 12:50:35 -- Version: -- Microsoft SQL Server 2012 - 11.0.5058.0 (X64) -- May 14 2014 18:34:29 -- Copyright (c) Microsoft Corporation -- Enterprise Edition: Core-based Licensing (64-bit) on Windows NT 6.3 <X64> (Build 9600: ) (Hypervisor) -- ---------------------------------------------------------------- --> 测试数据:[a] if object_id('[a]') is not null drop table [a] go create table [a]([NAME] varchar(2),[AGE] int) insert [a] select 'aa',18 union all select 'bb',21 union all select 'cc',22 union all select 'dd',25 union all select 'ff',19 --> 测试数据:[b] if object_id('[b]') is not null drop table [b] go create table [b]([NAME] varchar(2),[MOBILE] int) insert [b] select 'aa',11111111 union all select 'aa',22222222 union all select 'dd',33333333 union all select 'dd',44444444 union all select 'gg',55555555 union all select 'jj',66666666 --------------开始查询--------------------------SELECT a.* , b.* FROM a INNER JOIN b ON a.NAME = b.NAME WHERE a.AGE < 22 ----------------结果---------------------------- /* NAME AGE NAME MOBILE ---- ----------- ---- ----------- aa 18 aa 11111111 aa 18 aa 22222222 */
-- Author :DBA_HuangZJ(發糞塗牆)
-- Date :2014-07-08 12:50:35
-- Version:
-- Microsoft SQL Server 2012 - 11.0.5058.0 (X64)
-- May 14 2014 18:34:29
-- Copyright (c) Microsoft Corporation
-- Enterprise Edition: Core-based Licensing (64-bit) on Windows NT 6.3 <X64> (Build 9600: ) (Hypervisor)
--
----------------------------------------------------------------
--> 测试数据:[a]
if object_id('[a]') is not null drop table [a]
go
create table [a]([NAME] varchar(2),[AGE] int)
insert [a]
select 'aa',18 union all
select 'bb',21 union all
select 'cc',22 union all
select 'dd',25 union all
select 'ff',19
--> 测试数据:[b]
if object_id('[b]') is not null drop table [b]
go
create table [b]([NAME] varchar(2),[MOBILE] int)
insert [b]
select 'aa',11111111 union all
select 'aa',22222222 union all
select 'dd',33333333 union all
select 'dd',44444444 union all
select 'gg',55555555 union all
select 'jj',66666666
--------------开始查询--------------------------SELECT a.* ,
b.*
FROM a
INNER JOIN b ON a.NAME = b.NAME
WHERE a.AGE < 22
----------------结果----------------------------
/*
NAME AGE NAME MOBILE
---- ----------- ---- -----------
aa 18 aa 11111111
aa 18 aa 22222222
*/