SQL与Like运算符联接

时间:2019-04-20 21:07:48

标签: sql sql-server sql-server-2012

我有这样的桌子

tableUser:

id   | name
-----+------------
1    | John Smith
2    | Maria
3    | peter

tableComplaint

id   | ComplaintIssue   | User
-----+------------------+-----
1    | Isssue1          |  1
2    | Issue nth        |  3
3    | Issue infinity   |  4 

现在我正试图从下面的查询中获取输出

select 
    tc.id, tc.complaintissue, tu.name tc 
from 
    tablecomplaint tc
join 
    tbuser tu on tu.id = tc.user
where 
    tc.comlaintissue like '%%' or tu.name like '%%'

但是我无法在tu.name上放置类似运算符。

我希望我的输出查询也允许使用用户名搜索。

2 个答案:

答案 0 :(得分:2)

您两次出现“ tc”

select tc.id, tc.complaintissue, tu.name [->]tc from tablecomplaint [->] tc
join tbuser tu on tu.id = tc.user
where tc.comlaintissue like '%%' or tu.name like '%%'

你想表达什么意思?

select tc.id, tc.complaintissue, tu.name from tablecomplaint tc
join tbuser tu on tu.id = tc.user
where tc.comlaintissue like '%%' or tu.name like '%%'

答案 1 :(得分:0)

有效,

select 
    tc.id, tc.complaintissue, tu.name tc 
from 
    tablecomplaint tc
join 
    tbuser tu on tu.id = tc.user
where 
    tc.complaintissue like '%%' or tu.name like '%%'