select #f.ID,#f.title,#f.ty_xq,#f.ty_fydz,#f.c from #f , #x 这样是笛卡尔集,1000行*1000行=1000000 行(结果)
select #f.ID,#f.title,#f.ty_xq,#f.ty_fydz,#f.c from #f , #x 得到的是迪卡尔积 相当于cross join
select #f.ID,#f.title,#f.ty_xq,#f.ty_fydz,#f.c from #f , #x 迪卡尔积
你这是交叉连接,产生了迪卡尔积.你带上条件就行了.select #f.ID,#f.title,#f.ty_xq,#f.ty_fydz,#f.c from #f , #x where #f.关键字 = #x.关键字
---------------------------------------------------------------- -- Author :fredrickhu(我是小F,向高手学习) -- Date :2009-12-23 16:05:50 -- Version: -- Microsoft SQL Server 2005 - 9.00.4035.00 (Intel X86) -- Nov 24 2008 13:01:59 -- Copyright (c) 1988-2005 Microsoft Corporation -- Developer Edition on Windows NT 5.2 (Build 3790: Service Pack 1) -- ---------------------------------------------------------------- --> 测试数据:[a] if object_id('[a]') is not null drop table [a] go create table [a]([col] int) insert [a] select 1 union all select 2 union all select 3 union all select 4 --> 测试数据:[b] if object_id('[b]') is not null drop table [b] go create table [b]([2] int) insert [b] select 3 union all select 4 --------------开始查询-------------------------- select * from a,b ----------------结果---------------------------- /*col 2 ----------- ----------- 1 3 2 3 3 3 4 3 1 4 2 4 3 4 4 4(8 行受影响) */--------------开始查询-------------------------- select * from a cross join b ----------------结果---------------------------- /* col 2 ----------- ----------- 1 3 2 3 3 3 4 3 1 4 2 4 3 4 4 4(8 行受影响) */ --------------开始查询-------------------------- select * from a ----------------结果---------------------------- /* col ----------- 1 2 3 4(4 行受影响) */
select #f.ID,#f.title,#f.ty_xq,#f.ty_fydz,#f.c from #f , #x where #f.c = #x.c and #f.ty_xq like '%芳古园二区%'(1000 行受影响)匹配上 “芳古园二区”只有一行,但重复显示了1000次。
from #f , #x 知道這是什么意思嗎?
from #f , #x 这样是笛卡尔集,1000行*1000行=1000000 行(结果)
from #f , #x
得到的是迪卡尔积 相当于cross join
from #f , #x
迪卡尔积
from #f , #x
where #f.关键字 = #x.关键字
-- Author :fredrickhu(我是小F,向高手学习)
-- Date :2009-12-23 16:05:50
-- Version:
-- Microsoft SQL Server 2005 - 9.00.4035.00 (Intel X86)
-- Nov 24 2008 13:01:59
-- Copyright (c) 1988-2005 Microsoft Corporation
-- Developer Edition on Windows NT 5.2 (Build 3790: Service Pack 1)
--
----------------------------------------------------------------
--> 测试数据:[a]
if object_id('[a]') is not null drop table [a]
go
create table [a]([col] int)
insert [a]
select 1 union all
select 2 union all
select 3 union all
select 4
--> 测试数据:[b]
if object_id('[b]') is not null drop table [b]
go
create table [b]([2] int)
insert [b]
select 3 union all
select 4
--------------开始查询--------------------------
select * from a,b
----------------结果----------------------------
/*col 2
----------- -----------
1 3
2 3
3 3
4 3
1 4
2 4
3 4
4 4(8 行受影响)
*/--------------开始查询--------------------------
select * from a cross join b
----------------结果----------------------------
/* col 2
----------- -----------
1 3
2 3
3 3
4 3
1 4
2 4
3 4
4 4(8 行受影响)
*/
--------------开始查询--------------------------
select * from a
----------------结果----------------------------
/* col
-----------
1
2
3
4(4 行受影响)
*/
select #f.ID,#f.title,#f.ty_xq,#f.ty_fydz,#f.c
from #f , #x
where #f.c = #x.c and #f.ty_xq like '%芳古园二区%'(1000 行受影响)匹配上 “芳古园二区”只有一行,但重复显示了1000次。