Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 122
  • Last Modified:

SQL syntax for like using another field in another table

I have two tables.
ChemoDrugList
DrugList
and the only field common between the two will not match precisely, although they have the same naming convention.
Example, where ChemoDrugList might have a drugname like AFINITOR 10MG TAB the DrugList table would have AFINITOR or AFINITOR CHLORIDE. One convention that might be useful is that up the 1st space in either table would be a good place to stop the comparison.

What I need to do is somehow do something that might look like this
SELECT * FROM ChemoDrugList, DrugList
where ??? something here where I can say compare each field up to the space ???
0
ghettocounselor
Asked:
ghettocounselor
  • 3
  • 2
1 Solution
 
Nathan RileyFounderCommented:
What field do you join on in both?

Something like this would do it.

select *
from ChemoDrugList cdl, DrugList dl
where cdl.fieldname like '%afinitor%'
and dl.fieldname like '%afinitor%'

Open in new window

0
 
ghettocounselorPharmacy Systems AdminAuthor Commented:
drugName is field name

so how do I deal with the fact that the name in the field will one minute be afinitor and the next lidocaine, there are about 5000 records in each table.
0
 
Nathan RileyFounderCommented:
I'm not sure what you mean? You didn't say that they fields are changing in the question above, just that they have similar names, but not exact matches.
0
What Kind of Coding Program is Right for You?

There are many ways to learn to code these days. From coding bootcamps like Flatiron School to online courses to totally free beginner resources. The best way to learn to code depends on many factors, but the most important one is you. See what course is best for you.

 
Michael FowlerSolutions ConsultantCommented:
Use the LIKE predicate
http://www.w3schools.com/sql/sql_like.asp

SELECT *
FROM ChemoDrugList CDL INNER JOIN DrugList DL
ON CDL.drugname LIKE DL.drugname + '%'
Where CDL.drugname = 'lidocaine'
0
 
ghettocounselorPharmacy Systems AdminAuthor Commented:
Looks good, thanks!
0
 
ghettocounselorPharmacy Systems AdminAuthor Commented:
Still having a bit of trouble on this one after digging into it.

query example
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

A proven path to a career in data science

At Springboard, we know how to get you a job in data science. With Springboard’s Data Science Career Track, you’ll master data science  with a curriculum built by industry experts. You’ll work on real projects, and get 1-on-1 mentorship from a data scientist.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now