MySQL alternative to union? -


i'm trying think of alternative method use instead of union.

i have 20 queries this, plan connect via union, prevent multiple mysql connections.

$data = $db2->query("select parent.*,link.tag_id tag_id items parent             join relations link on link.item_id=parent.id             join tags child on child.id=link.tag_id             child.handle='$handle' limit ".$limit.",1"); 

instead of doing query 20 times , connecting them via union, there alternate method simplify full query or union best method? both handle , $limit dynamic each select query.

how solve?

alternatively, instead of using limit

$data = $db2->query("select parent.*,link.tag_id tag_id items parent                 join relations link on link.item_id=parent.id                 join tags child on child.id=link.tag_id                 child.handle='$handle' , parent.`no`='$limit' limit 1"); 

if don't have different limit amounts each query, can combine them single query uses or. 1 value each child.handle , parent.no, can use group by.

$data = $db2->query("select parent.*,link.tag_id tag_id items parent             join relations link on link.item_id=parent.id             join tags child on child.id=link.tag_id             (child.handle='$handle1' , parent.`no`='$limit1')             or (child.handle='$handle2' , parent.`no`='$limit2')             or (child.handle='$handle3' , parent.`no`='$limit3')             or (child.handle='$handle4' , parent.`no`='$limit4')             ...             group child.handle, parent.no"); 

however, might not better doing union query, mysql not @ optimizing queries or conditions.


Comments

Popular posts from this blog

gridview - Yii2 DataPorivider $totalSum for a column -

java - Suppress Jboss version details from HTTP error response -

Sass watch command compiles .scss files before full sftp upload -