Skip to content
This repository was archived by the owner on Sep 20, 2021. It is now read-only.
This repository was archived by the owner on Sep 20, 2021. It is now read-only.

Alias in FROM clause. #12

@Metalaka

Description

@Metalaka

Hello,

I'm trying to use a Hoa\Database\Query\Select object in an INNER JOIN clause.

My goal is to get the following query:

SELECT *
FROM Foo AS F
INNER JOIN (
  SELECT *
  FROM Bar
) AS B
ON F.Foo_ID = B.Bar_ForeignKey

But I wasn't able to alias correctly my two sources.

  • For the Foo table I can make an alias without the keyword AS like from('Foo F').
  • The second alias is not well placed due to the ON clause (it's work well without).

There are my test code and the output.

$req = new \Hoa\Database\Query\Select();
$req->from('Foo')
    ->_as('F')
    ->innerJoin(
        (new \Hoa\Database\Query\Select())
            ->from('Bar')
    )
    ->on('F.Foo_ID = B.Bar_ForeignKey')
    ->_as('B');
SELECT *
FROM Foo
INNER JOIN (
  SELECT *
  FROM Bar
)
ON F.Foo_ID = B.Bar_ForeignKey
AS B

PS: Moreover the fact to don't alias an Hoa\Database\Query\Select object in an INNER JOIN clause throw a SQL error : #1248 - Every derived table must have its own alias.


Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions