How can I determine whether a keyword composed of multiple fields exists in another table?

Source: Internet
Author: User
Tags keyword list

How can I determine whether a keyword composed of multiple fields exists in another table?

How can I determine whether a keyword composed of multiple fields exists in another table?

Old Shuai (20141107)

1. First, it is easy to determine whether a keyword exists in another table!

SELECT * FROM

WHERE a. ID

IN

(

SELECT B. ID

FROM B

)


2. What if the keyword to be judged has multiple fields?

You cannot use multiple fields IN. Query as follows:

SELECT * FROM

WHERE (a. ID1, a. ID2)

IN

(

SELECT B. ID1, B. ID2

FROM B

)

This does not work normally and violates the SQL Server Standard.


3. To solve this problem, use EXISTS instead of IN!

SELECT * FROM

WHERE EXISTS

(

SELECT NULL

FROM B

WHERE a. ID1 = B. ID1

AND a. ID2 = B. ID2

)


4. It is worth noting that this applies only to IN, not in!

Not in and not exists are slightly different IN the way of processing null values.

SELECT *

FROM

WHERE (a. ID1, a. ID2) NOT IN

(

SELECT B. ID1, B. ID2

FROM B

)

This does not work normally and violates the SQL Server Standard. The query to imitate not in is as follows:

We must use the following query:

SELECT *

FROM

WHERE NOT EXISTS

(

SELECT NULL

FROM B

WHERE a. ID1 = B. ID1

AND a. ID2 = B. ID2

)

AND NOT EXISTS

(

SELECT NULL

FROM B

WHERE B. ID1 IS NULL

OR B. ID2 IS NULL

)

The second predicate ensures that B does not have null values in ID1 and ID2. Any such value will prevent the original query from returning results!


Use the fields of one table as keywords in access to find records that contain these keywords in one field of another table.

I'm dizzy... so complicated... left join...
And there must be something wrong with your results... 4. Where did it come from?

Select Table B. Record, Table A. Details
From table B left join Table
On Table B. Record = Table A. Record

.............
I'm not sure whether access left join and full join can be used...
But I remember it.

In excel, how does one query whether a field contains a keyword in the keyword list?

D1 cell write formula
= COUNT (FIND (A $1: A $5, C1)> 0
Or
= OR (ISNUMBER (FIND (A $1: A $5, C1 )))
Array formula. Press SHIFT + CTRL + ENTER to fill the formula in the drop-down list.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.