Answered by:
Join two columns from two different tables where both the columns have partially similar data

Question
-
I have two tables, [A] and [B]. I want to join both tables on the [City] column from table [A] and [Cities renown for] column from table [B].
So the [City] column from table [A] looks like this.
[City]
______________
Orlando
New York
Los Angeles
and the [Cities renown for] column from table [B] looks like this.
[Cities renown for]
_________________________________________________________
New York_Status of Liberty
Orlando_Disney World
Los Angeles_Hollywood
My tables have about ten thousand rows each and I want to match the columns based on the city names like Orlando = Orlando_Disney World
So I have written my query like this.
Select a.[City]
from [A] as a
inner join [B] as b
on a.[City] = b.[Cities renown for]
where a.[City] = b.[Cities renown for]
I know I am doing the last two lines wrong but don't know really how to fix it
- Edited by tkhan17 Wednesday, July 18, 2018 7:33 PM
Wednesday, July 18, 2018 7:18 PM
Answers
-
I'd ask for help over here.
https://social.msdn.microsoft.com/Forums/sqlserver/en-US/home?category=sqlserver
https://answers.microsoft.com/en-us/msoffice/forum/msoffice_access
https://social.msdn.microsoft.com/forums/office/en-us/home?forum=accessdev
Regards, Dave Patrick ....
Microsoft Certified Professional
Microsoft MVP [Windows Server] Datacenter Management
Disclaimer: This posting is provided "AS IS" with no warranties or guarantees, and confers no rights.- Proposed as answer by Richard MuellerMVP, Banned Wednesday, July 18, 2018 9:30 PM
- Marked as answer by Richard MuellerMVP, Banned Wednesday, July 25, 2018 12:07 PM
Wednesday, July 18, 2018 7:36 PM
All replies
-
I'd ask for help over here.
https://social.msdn.microsoft.com/Forums/sqlserver/en-US/home?category=sqlserver
https://answers.microsoft.com/en-us/msoffice/forum/msoffice_access
https://social.msdn.microsoft.com/forums/office/en-us/home?forum=accessdev
Regards, Dave Patrick ....
Microsoft Certified Professional
Microsoft MVP [Windows Server] Datacenter Management
Disclaimer: This posting is provided "AS IS" with no warranties or guarantees, and confers no rights.- Proposed as answer by Richard MuellerMVP, Banned Wednesday, July 18, 2018 9:30 PM
- Marked as answer by Richard MuellerMVP, Banned Wednesday, July 25, 2018 12:07 PM
Wednesday, July 18, 2018 7:36 PM -
i think I posted in where you are referring to. I am really confused now.Wednesday, July 18, 2018 7:43 PM
-
This is "where is" forum for direction on where best to ask questions. I see a similar question here.
or you can also review your other threads posted on MSDN/TechNet forums here.
https://social.msdn.microsoft.com/Profile/tkhan17/activity
Regards, Dave Patrick ....
Microsoft Certified Professional
Microsoft MVP [Windows Server] Datacenter Management
Disclaimer: This posting is provided "AS IS" with no warranties or guarantees, and confers no rights.Wednesday, July 18, 2018 7:53 PM -
You can use Where clause or Join clause with Like operator.
1. Where Clause:
Select * From A, B Where B.[Cities renown for] Like '%' + A.City + '%';
2. Join Clause:
Select * From A Join B On B.[Cities renown for] Like '%' + A.City + '%'
If you are sure that the first part of the "[Cities renown for]" column would be the city name, then it's better to use the following condition for better performance:
B.[Cities renown for] Like A.City + '%'
- Edited by Ahmad Adel Gad Wednesday, July 18, 2018 8:24 PM
Wednesday, July 18, 2018 8:15 PM