如何获取其他表中存在的ID名称 [英] how to take id names present in some other table

查看:109
本文介绍了如何获取其他表中存在的ID名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我正在显示产品名称以及此处充当外键的类别ID和子类别ID ...,但我想显示存在于类别和子类别表中的ID名称...已经在一页中我要显示所有类别名称和子类别名称,并将它们各自的ID存储在产品表中...但是在一页中,我需要显示产品表中不存在的类别和子类别名称,而它们的ID是在此处存在...请帮助我

Hi,

I am displaying product names along with category id''s and subcategory id''s which are act as foreign key here...but i want to display id names which are present in category and subcategory table...already in one page i am displaying all category names and sub category names and storing their respective id''s in product table...but in one page i need to display category and subcategory names which are not present in product table instead their id''s are present here...please help me

推荐答案

如果我正确理解了这个问题,则可以使用NOT EXISTS来解决这个问题.像这样的东西:

If I understood the question correctly, you can use NOT EXISTS for this. Something like:

SELECT * 
FROM Category c
WHERE NOT EXISTS( SELECT 1
                  FROM Product p
                  WHERE p.CategoryId = c.CategoryId);


不存在或不存在,可以使用任何一个.
Not Exists or Not In, any one can be used.


这篇关于如何获取其他表中存在的ID名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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