Skip to content

Missleading select example #3

@duzun

Description

@duzun

My first experience with Plusql wasn't that good as it could be.

At first glance there is nothing complicated or strange about this example:

//get an escape function
$f = Plusql::escape($profile);

echo Plusql::from($profile)->strong_guy
                           ->weak_guy->select('strong_guy_id,weak_guy_id,strong_name,weak_name')
                           ->where('strong_guy_id = '.$f($_GET['something']))
                          ->orderBy('strong_guy_id,weak_guy_id);

But it made me think it uses USING(strong_guy_id) internally and I started writting queries with this conviction in my mind, just to discover later that actually this query can't be run as is

It translates to

SELECT strong_guy_id,weak_guy_id,strong_name,weak_name 
FROM strong_guy 
INNER JOIN weak_guy ON strong_guy.strong_guy_id = weak_guy.strong_guy_id 
WHERE strong_guy_id = 1 
ORDER BY strong_guy_id,weak_guy_id

Which results in an error:

#1052 - Column 'strong_guy_id' in field list is ambiguous

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions