如何基于联接检索项目 [英] How to retrive the items based on joins

查看:60
本文介绍了如何基于联接检索项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个表,一个是item表,其中包含itemid,itemname,itemprice,另一个用于userpermission,其中包含productid,userid.我想列出项目表中的项目,而不是特定用户的用户权限表中的项目.用户ID 1的意思是我要列出项目表中但不在用户权限中的项目.

用户ID存储在会话中的位置

I have two table one is item table which contains the itemid,itemname,itemprice and another for userpermission which contains productid,userid . I want to listed down the items which are in the item table but not in the userpermission table for a particular user. Means for userid 1 i want to list the items which are in item table but not in userpermission .

where Userid is stored in session

推荐答案

Select * from table1 Inner join table 2 on 
table1.FirstID = table2.FirstID

这是有关如何使用内部联接的语法,必须具有主键或外键
基本上是向您提出建议.,,
如果您使用的是SQL Server,最好放入SQL语句,然后尝试在数据库的新查询中执行它.这样,您可以轻松查看SQL命令的错误.

编码愉快

That is the syntax regarding on how to use Inner Join must have a primary key or a foreign key
Basically im proposing something to you.,,
If your using SQL server it is better to put in your SQL statement and try to execute it in new query of your database. In that way you can easily see what is the error of your SQL command.

Happy coding


Select * from Item where ItemID not in (select ItemID from UserPermission where UserID=ID)


尝试一下
declare @Id int
set @Id= 1
select * from Item I left outer join UserPermission U on I.ItemId = U.ItemId
where ItemId is null and userId = @Id


这篇关于如何基于联接检索项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆