SQL соединяется с оператором Like - PullRequest
0 голосов
/ 21 апреля 2019

У меня есть такие таблицы

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 ]

2 голосов
/ 21 апреля 2019

у вас дважды появляется "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 '%%'
0 голосов
/ 21 апреля 2019

это сработало,

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 '%%'
...