我有一个下面详细介绍的SQL,并希望有人可以帮助我优化这一点,因为我觉得它有点笨拙......感谢任何帮助,谢谢。
SELECT * FROM test.datalist
Where UserName Like '%SearchString%'
Or UserName In (
Select Synonym
From synonyms
Where Synonym Like '%SearchString%'
OR ListRef = ( Select ListRef
From synonyms
Where Synonym Like '%SearchString%')
);
感谢所有建议。
答案 0 :(得分:0)
如果您已经与Where Synonym Like '%SearchString%'
匹配,则子查询的下半部分没有任何意义,无法找到同一个表的ListRef
来获取Synonym
Where Synonym Like '%SearchString%'
OR ListRef = ( Select ListRef
From synonyms
Where Synonym Like '%SearchString%')
另外你可以尝试加入
SELECT * FROM datalist d
JOIN synonyms s ON (d.UserName =s.Synonym)
Where d.UserName Like '%SearchString%' or s.Synonym Like '%SearchString%'
我已根据d.UserName =s.Synonym
加入您的表格,如果您在这些表格之间存在特定关系,则应用该表格,并为您的列添加适当的索引