[英]Compare the strings of two tables in DB2 using SQL
What I want to do is to compare the strings of two tables: 我想做的是比较两个表的字符串:
Imagine I have tables called students and professors. 想象一下,我有一个叫学生和教授的桌子。 Both have an attribute called name.
两者都有一个名为name的属性。 Now I want to get those Studentnames that contain the name of one of the professors.
现在,我想获取包含一位教授姓名的学生姓名。 Of course I tried
我当然试过了
select s.name
from students s, professors p
where s.name like p.pame
but it says: 但它说:
SQL ERROR: An operand of LIKE is not a string, or the first operand is not a column.
select s.name
from students s
where s.name in ( select p.name from professors p);
Is this what you want? 这是你想要的吗? Other wise, maybe you need to write a cursor to fetch a profsseor.name one at a time, then find matched student in a loop.
否则,也许您需要编写一个游标来一次获取一个profsseor.name,然后在循环中找到匹配的学生。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.