Solved

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

Posted on 2016-09-01
2
60 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 29

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

Turn Insights Into Action

You’ve already invested in ITSM tools, chat applications, automation utilities, and more. Fortify these solutions with intelligent communications so you can drive business processes forward.

With xMatters, you'll never miss a beat.

Question has a verified solution.

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

Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.

689 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