Solved

Serch for terms within SQL table that exist in a second table

Posted on 2016-09-01
2
54 Views
Last Modified: 2016-09-12
I have a table of text terms that I want to search a second table to see if any of the Text Terms in the first table exist in a description in the second table excluding itself.

For clarity purposes I have attached an excel spreadsheet that shows an example of what I'm looking for.

The first column of data is in table # 1 (tmpTextIDTable) and contains a single column of text entries labeled TextID.
Columns E and F reference table #2 (tmpTextMatchDetails) which contain two columns TextID and TextDescription.

TextId is the key field to join the two tables.

You will not that the rows marked with either yellow or green, contain a reference to one or more references to the TextID text from table 1, however references to its own TextID is excluded.

I essentially want to create a list that tells me which rows from table two have a reference to any of the textid excluding itself.

Does this make sense?

Thanks for any direction you have
TextMatch.xlsx
0
Comment
Question by:jdr0606
2 Comments
 
LVL 28

Accepted Solution

by:
Pawan Kumar earned 500 total points
ID: 41780907
Use below approach..

Solution 1

---------------------------------------

SELECT Words.Texts Word , r.Texts Texts
FROM Words
CROSS APPLY
(
    SELECT Texts FROM Texts
)r
WHERE CHARINDEX(Words.Texts,r.Texts,0) > 0

SOLUTION 2

-------------------------------------

SELECT Words.Texts Word , r.Texts Texts
FROM Words
CROSS JOIN Texts r
WHERE CHARINDEX(Words.Texts,r.Texts,0) > 0


URL for ref --
https://msbiskills.com/2016/07/06/sql-puzzle-word-search-puzzle/


Enjoy ! Let me know in case you want me to write the exact query.. for that you need to share your table design for both the tables.
0
 

Author Comment

by:jdr0606
ID: 41794121
That gave what I needed to make it work

Thanks
0

Featured Post

Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.

789 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question