Skip to content

Across table conditions #85

Open
Open

Description

@prasad83

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)

Activity

  1. prasad83 commented on Jun 21, 2017

    @prasad83
    ContributorAuthor

    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";
    
  2. nilportugues commented on Jun 21, 2017

    @nilportugues
    Owner

    not for the time being

  3. marcus-hiles commented on Mar 29, 2019

    @marcus-hiles

    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions