# MySQL: Union and Like



## bob121 (Sep 10, 2006)

I'm having a problem, MySQL returns an error when i use Union.

The Query which returns an error


```
$query = "SELECT * FROM `write` UNION(SELECT * FROM `draw`) WHERE `title` LIKE '%".$keywords[$i]."%' OR `text` LIKE '%".$keywords[$i]."%' ORDER BY `dbdate` DESC";
```
Working Query


```
$query = "SELECT * FROM `write` WHERE `title` LIKE '%".$keywords[$i]."%' OR `text` LIKE '%".$keywords[$i]."%' ORDER BY `dbdate` DESC";
```
Also on the same page, I have Union queries running on the same two Tables and it works fine, for example


```
$result = mysql_query("SELECT * FROM `write` UNION(SELECT * FROM `draw`) ORDER BY `dbdate` DESC LIMIT $start, $limit");
```


----------



## maneetpuri (Oct 14, 2008)

Hi,

Try using the query below: -

$query = "SELECT * FROM `write` WHERE `title` LIKE '%".$keywords[$i]."%' OR `text` LIKE '%".$keywords[$i]."%' ORDER BY `dbdate` DESC UNION(SELECT * FROM `draw`)";

Hope this works!

Cheers,

~Maneet
LeXolution IT Services
Website Design Company


----------

