我有mysql表:
id | nameEng | NameRus
1 | Moscow | Москва
2 | London | Лондон
我想要的是:
$result = array (
1 => array (id => 1, Name => "Москва"),
2 => array (id => 1, Name => "Moscow"),
3 => array (id => 2, Name => "London"),
4 => array (id => 2, Name => "Лондон")
)
这是我的问题:
mysql_query("SELECT id, nameRus FROM citynames WHERE nameRus LIKE '%".$_GET['chars']."%'
UNION ALL
SELECT id, nameEng FROM citynames WHERE nameEng LIKE '%".$_GET['chars']."%' ORDER BY nameEng LIMIT 0, 10"
查询工作但我想优化此查询
答案 0 :(得分:0)
$l = "like '%". $_GET['chars'] ."%'";
$sql = "(select `id` as `id`, `nameEng` as `name` from `citynames `) union (select `id` as `id`, `NameRus` as `name` from `citynames `) where `name` $l order by `id`;";