使用单行查询检查两个表中是否存在记录 [英] check whether record exists in either tables using single line query
本文介绍了使用单行查询检查两个表中是否存在记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,
我在sql中有一个奇怪的疑问,疑问如下所述:
我有两个表A和B,现在我有一个参数,我想检查参数中的值是否存储在单个行查询中的表A或B中。(即不是两个查询检查两张表的价值)我怎样才能实现这个目标?
例如。表A和B
值= 5
检查A或B中是否存在5或两者都有...
请帮帮我..
谢谢
Hello everyone,
I have one odd doubt in sql, the doubt is as described below:
I have two tables A and B, now i have one parameter which i want to check whether the value in the parameter is stored in either of table A or B in a single line query.. (i.e. not two queries for checking value in two tables) how can i achieve this?
Eg. Table A and B
Value = 5
to check whether 5 is present in A or in B or in Both...
Please help me out with it..
Thanks
推荐答案
您可以定义另一个用户定义的函数,您可以在其中检查上述要求并返回值。
赞0 - 任何表格都不存在
1-表A中存在
2-存在于表B中
3-存在于两个表中。
只需在需要的地方调用此UDF。
You define another user defined function where you can check above requirement and return a value.
Like 0 - Not exist in any table
1- Exist in Table A
2- Exist in Table B
3- Exist in both table.
Just call this UDF where needed.
您好b $ b
请参阅示例
http://stackoverflow.com/questions/18924775/check-for-multiple-tables-existence-using-single-exists-query [ ^ ]
Hi
Please see the examples
http://stackoverflow.com/questions/18924775/check-for-multiple-tables-existence-using-single-exists-query[^]
这篇关于使用单行查询检查两个表中是否存在记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文