我的 php 脚本中有一个 sql 语法,它给了我一个错误。我想要的只是得到 2 sql statemet 的结果。
$sql1 = " SELECT `name`, `surname`, `email`, `user_id` FROM users WHERE (surname LIKE '$name%' AND name LIKE '$surname%') OR (surname LIKE '$surname%' AND name LIKE '$name%') ";
和
$sql2 = " SELECT profile_id from profile WHERE `country`='uk' ";
我想从我的数据库中获取 $sql1 和 $sql2 的值。我使用这样的 UNION 语句,但它不起作用。任何想法如何解决它:
$sql = " (SELECT `name`, `surname`, `email`, `user_id` FROM users WHERE (surname LIKE '$name%' AND name LIKE '$surname%') OR (surname LIKE '$surname%' AND name LIKE '$name%')) UNION (SELECT profile_id from profile WHERE `country`='uk' ) ";