--User 表中有100 萬條資料
CREATE TABLE [User](
[UserID] [int] IDENTITY(1,1) NOT NULL,
[OrganizationID] [int] NOT NULL,
[UserName] [nvarchar](100) NOT NULL,
[Password] [nvarchar](max) NULL,
)
--[UserSettings] 表中有200 萬條資料
CREATE TABLE [UserSettings](
[UserSettingId] [int] IDENTITY(1,1) NOT NULL,
[UserId] [int] NOT NULL,
[SettingKey] [nvarchar](100) NOT NULL,
[SettingValue] [nvarchar](500) NOT NULL
)
--假如用戶表有 user1 and user2 ,請用不同的方式找到user1 和user2 的setting 資訊,并決議不同查找方式的優劣
uj5u.com熱心網友回復:
select t1.* from usersetting t1,user t2where t1.userid = t2.userid
and t2.username in ('user1','user2');
select * from usersetting t1
where exists (select 1 from user t2 where t1.userid = t2.userid and t2.username in ('user1','user2'));
感覺兩個都會走嵌套,user表的主鍵在這里沒啥作用
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/29790.html
標籤:認證與考試
上一篇:SFTP上傳檔案
