Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Across table conditions #85

Open
prasad83 opened this issue Jun 21, 2017 · 3 comments
Open

Across table conditions #85

prasad83 opened this issue Jun 21, 2017 · 3 comments

Comments

@prasad83
Copy link
Contributor

I would like to know how to build the query like below that has conditions across tables.

SELECT TableA.ColA, TableB.ColB
FROM TableA
INNER JOIN TableB ON TableA.id=TableB.id
WHERE (TableA.ColX = TableB.ColX OR TableA.ColY > TableB.ColY) AND (TableA.ColZ < TableB.ColZ)
@prasad83
Copy link
Contributor Author

prasad83 commented Jun 21, 2017

Is there a simpler way than this?

use NilPortugues\Sql\QueryBuilder\Syntax\Column;
use NilPortugues\Sql\QueryBuilder\Manipulation\Select;
$select = new Select("TableA");
$select->setColumns(array("ColA"));
$select->innerJoin("TableB", "id", "id", array("ColB"));
$where = $select->where();
$where->subWhere()
    ->equals("ColX", new Column("ColX", "TableB"))
    ->greaterThan("ColY", new Column("ColY", "TableB"));
$where->subWhere()
    ->lessThan("ColZ", new Column("ColZ", "TableB"));
use NilPortugues\Sql\QueryBuilder\Builder\MySqlBuilder;
$builder = new MySqlBuilder();
echo $builder->writeFormatted($select) . "\n";

@nilportugues
Copy link
Owner

not for the time being

@marcus-hiles
Copy link

Simpler way would be raw mysql query @prasad83

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants