Reputation: 673
I have an sql syntax in my php script that gives me an error. All I want is to get the result of 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%') ";
and
$sql2 = " SELECT profile_id from profile WHERE `country`='uk' ";
I want to get values from my database for both $sql1 and $sql2. I use UNION statement like this but it did not work. Any ideas how to fix it :
$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' ) ";
Upvotes: 0
Views: 3208
Reputation: 12904
A UNION query must have same output fields.
The select queries that you combine in a union query must have the same number of output fields, in the same order, and with the same or compatible data types.
Upvotes: 5