1

I want to create a search engine in my site, but have one problem can I select all values from two or more different tables with one query, because have one category exp. News and in this category have subcategories and every subcategory have other tables and if I select News I need to get all values from subcategories tables.

Exp. tables: first table name is test1, second table name is test2:

id|title|content|
1|dog|dog is big|
2|cat|cat is small|

id|title|content|
1|plant|plant1|
2|stone|stone1|

And I need to get all values from this tables.

1 Answer 1

2

Well, looks like you need to build a union here:

$db = Zend_Db::factory( ...options... );
$select = $db->select()
    ->union(array(
        $db->select()
            ->from(array('t1' => 'test1'))
            ->where(/* search criteria goes here */),
        $db->select()
            ->from(array('t2' => 'test2'))
            ->where(/* search criteria goes here as well */)
        ));

Alternatively, you may want to look at Sphinx.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.