id name pass message sigan
3 ff fff ggg 0
4 tt tt ttt 1
5 gg gg gg 0
6 ee ee ee 1
7 hh hh hh 1
8 kk kkk kk 0以上是我举的数据信息 我现在想要得到ID 为5 并且 sign为1的 数据信息
id name pass message sigan
4 tt tt ttt 1
5 gg gg gg 0
6 ee ee ee 1
7 hh hh hh 1
不知道有办法吗 请帮助
3 ff fff ggg 0
4 tt tt ttt 1
5 gg gg gg 0
6 ee ee ee 1
7 hh hh hh 1
8 kk kkk kk 0以上是我举的数据信息 我现在想要得到ID 为5 并且 sign为1的 数据信息
id name pass message sigan
4 tt tt ttt 1
5 gg gg gg 0
6 ee ee ee 1
7 hh hh hh 1
不知道有办法吗 请帮助
--> Author : wufeng4552
--> Date : 2009-11-05 10:25:14
if object_id('[tb]') is not null drop table [tb]
go
create table [tb] (id int,name nvarchar(4),pass nvarchar(6),message nvarchar(6),sigan int)
insert into [tb]
select 3,'ff','fff','ggg',0 union all
select 4,'tt','tt','ttt',1 union all
select 5,'gg','gg','gg',0 union all
select 6,'ee','ee','ee',1 union all
select 7,'hh','hh','hh',1 union all
select 8,'kk','kkk','kk',0
select * from [tb] where sigan=1
union all
select * from [tb] where id=5
order by id
/*
id name pass message sigan
----------- ---- ------ ------- -----------
4 tt tt ttt 1
5 gg gg gg 0
6 ee ee ee 1
7 hh hh hh 1(4 個資料列受到影響)
*/
select * from tablname where id = 5 or sigan = 1
-- Author :fredrickhu(我是小F,向高手学习)
-- Date :2009-11-05 10:27:12
-- 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)
--
----------------------------------------------------------------
--> 测试数据:[tb]
if object_id('[tb]') is not null drop table [tb]
go
create table [tb]([id] int,[name] varchar(2),[pass] varchar(3),[message] varchar(3),[sigan] int)
insert [tb]
select 3,'ff','fff','ggg',0 union all
select 4,'tt','tt','ttt',1 union all
select 5,'gg','gg','gg',0 union all
select 6,'ee','ee','ee',1 union all
select 7,'hh','hh','hh',1 union all
select 8,'kk','kkk','kk',0
--------------开始查询--------------------------select * from [tb] where id=5 or sigan=1
----------------结果----------------------------
/* id name pass message sigan
----------- ---- ---- ------- -----------
4 tt tt ttt 1
5 gg gg gg 0
6 ee ee ee 1
7 hh hh hh 1(4 行受影响)
*/
--借 水的数据
if object_id('[tb]') is not null drop table [tb]
go
create table [tb] (id int,name nvarchar(4),pass nvarchar(6),message nvarchar(6),sigan int)
insert into [tb]
select 3,'ff','fff','ggg',0 union all
select 4,'tt','tt','ttt',1 union all
select 5,'gg','gg','gg',0 union all
select 6,'ee','ee','ee',1 union all
select 7,'hh','hh','hh',1 union all
select 8,'kk','kkk','kk',0
select * from [tb] where id = 5 or sigan = 1==========id name pass message sigan
----------- ---- ------ ------- -----------
4 tt tt ttt 1
5 gg gg gg 0
6 ee ee ee 1
7 hh hh hh 1(4 行受影响)
“并且”对应的是 and
-- Author :fredrickhu(我是小F,向高手学习)
-- Date :2009-11-05 10:27:12
-- 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)
--
----------------------------------------------------------------
--> 测试数据:[tb]
if object_id('[tb]') is not null drop table [tb]
go
create table [tb]([id] int,[name] varchar(2),[pass] varchar(3),[message] varchar(3),[sigan] int)
insert [tb]
select 3,'ff','fff','ggg',0 union all
select 4,'tt','tt','ttt',1 union all
select 5,'gg','gg','gg',0 union all
select 6,'ee','ee','ee',1 union all
select 7,'hh','hh','hh',1 union all
select 8,'kk','kkk','kk',0
--------------开始查询--------------------------select * from [tb] where id=5 or sigan=1
----------------结果----------------------------
/* id name pass message sigan
----------- ---- ---- ------- -----------
4 tt tt ttt 1
5 gg gg gg 0
6 ee ee ee 1
7 hh hh hh 1(4 行受影响)
*/
if object_id [[tb] is not null drop table [tb]
GO
create table [tb](id int,name nvarchar(20),pass nvarchar(4),message nvarchar(40),sigan int)
insert [tb] select '3','ff','fff','ggg','0' union all
select '4','tt','tt', 'ttt', '1'union all
select '5','gg' ,'gg','gg' , '0' union all
select '6','ee', 'ee','ee' ,'1' union all
select '7' ,'hh' ,'hh', 'hh','1' union all
select '8', 'kk' ,'kkk','kk', '0'
--数据查询
select * from [tb] where sigan=1
union all
select * from [tb] where id=5
order by id
insert [tb]
select 3,'ff','fff','ggg',0 union all
select 4,'tt','tt','ttt',1 union all
select 5,'gg','gg','gg',0 union all
select 6,'ee','ee','ee',1 union all
select 7,'hh','hh','hh',1 union all
select 8,'kk','kkk','kk',0--1
select * from tb where id = 5 or sigan = 1 order by id --2
select * from tb where id = 5
union all
select * from tb where sigan = 1
order by id drop table tb/*
id name pass message sigan
----------- ---- ---- ------- -----------
4 tt tt ttt 1
5 gg gg gg 0
6 ee ee ee 1
7 hh hh hh 1(所影响的行数为 4 行)*/
------------------------------------------
看你结果数据你的描述应该为:
ID 为5 或者 sign为1id=5 or sign=1
WHERE id = 5 AND sigan = 1
/
from tb
where id=5 and sigan=1
IF(OBJECT_ID('TEMPDB..#T') IS NOT NULL)
BEGIN
DROP TABLE #T
END
CREATE TABLE #T
(
[ID] INT,
[NAME] NVARCHAR(100),
[PASS] NVARCHAR(100),
[MESSAGE] NVARCHAR(1000),
[SIGAN] INT
)
INSERT INTO #T SELECT 3,'FF','FFF','GGG',0
INSERT INTO #T SELECT 4,'TT','TT','TTT',1
INSERT INTO #T SELECT 5,'GG','GG','GG',0
INSERT INTO #T SELECT 6,'EE','EE','EE',1
INSERT INTO #T SELECT 7,'HH','HH','HH',1
INSERT INTO #T SELECT 8,'KK','KKK','KK',0SELECT * FROM #T WHERE [ID]=5 OR [SIGAN]=1
-------------------------------------------
4 TT TT TTT 1
5 GG GG GG 0
6 EE EE EE 1
7 HH HH HH 1
select * from tablname where id = 5 and sigan = 1貌似是 and 吧
最好加上括号 如果你还有其他查询条件的话
insert [tb]
select 3,'ff','fff','ggg',0 union all
select 4,'tt','tt','ttt',1 union all
select 5,'gg','gg','gg',0 union all
select 6,'ee','ee','ee',1 union all
select 7,'hh','hh','hh',1 union all
select 8,'kk','kkk','kk',0--1
select * from tb where id = 5 or sigan = 1 order by id --2
select * from tb where id = 5
union all
select * from tb where sigan = 1
order by id drop table tb/*
id name pass message sigan
----------- ---- ---- ------- -----------
4 tt tt ttt 1
5 gg gg gg 0
6 ee ee ee 1
7 hh hh hh 1(所影响的行数为 4 行)*/