MS Access SQL无法正常工作 [英] MS Access SQL Not Working as desired

查看:77
本文介绍了MS Access SQL无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个类似这样的查询.

I have a query which goes like this.

SELECT * FROM <database1> WHERE (Condition1) AND (Condition2 or Condition3)

SELECT * FROM <database1> WHERE (Condition1) AND (Condition2 or Condition3)

我想要的结果应该是满足条件1的行和满足条件2或条件3的行.

My desired result should be rows satisfying condition1 and rows satisfying either condition 2 or condition3.

但是SQL给我的行仅满足condition1.看来condition2和condition3之间的'OR'运算符正在做某事.

But the SQL is giving me rows that are just satisfying condition1. It seems that the 'OR' operator between the condition2 and condition3 is doing something.

寻求专家意见.预先感谢您的帮助.

Expert opinion sought. Thanks in advance for the help.

推荐答案

在您的评论中,您输入:

In your comment you put:

SELECT * 
FROM <Database> 
WHERE 
    (
        (   [Title] Like '*Term1*' 
         OR [Title] = '' 
         OR [Title] = '' 
         OR [Title] = '' 
         OR [Title] = '' 
         OR [Title] = '' 
         OR [Title] = '' 
         OR [Title] = '' 
         OR [Title] = '' 
         OR [Title] = ''
        ) 
    and 
        (
            (   [Title] LIKE '*Term1*' 
             OR '*Term3*' 
             OR '*Indonesia*' 
             or [Country] IN ('*India*','*Indonesia*')
            )
        )
    )

这样布置,您可以更轻松地看到结构.

Laid out like this you can see the structure a bit easier.

第二部分中可能将LIKEORIN运算符混合使用的最大功能是.

The biggest thing that is probably throwing you is the mix of LIKE, OR and IN operators in the second part.

LIKE是唯一可以处理通配符的运算符,而ORIN则不能.

LIKE is the only operator that can deal with wildcards, OR and IN can't.

您可能想要的意思是:

            (   [Title] LIKE '*Term1*' 
             OR [Title] LIKE '*Term3*' 
             OR [Title] LIKE '*Indonesia*' 
             OR [Country] LIKE '*India*'
             OR [Country] LIKE '*Indonesia*'
            )

相反.

这篇关于MS Access SQL无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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