我想在 PDO 中进行查询并将结果返回给 JSON 数组,以便在自动完成中使用它。表格中有3列,像这样
ID | Plaatsnaam | Alternatief
1 | Beetgum | Bitgum
2 | Beesterzwaag |
3 | Beetgummermolen | Bitgummole
4 | Bierum |
5 | Birdaard |
现在我想写一个查询来返回 plaatsnaam 或 (!) 以 'Bi' 开头的 alternatief,所以查询的结果必须是:
Bitgum,
Bitgummole,
Bierum,
Birdaard
怎么做?
最佳答案
尝试使用两个查询并使用联合来获取所有结果。
SELECT Plaatsnaam as rst from table where Plaatsnaam like 'yourinput%'
UNION
SELECT Alternatief as rst from table where Alternatief like 'yourinput%'
关于MYSQL 语句结果来自 2 列,具体取决于位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26647699/