catfan / Medoo

The lightweight PHP database framework to accelerate the development.
https://medoo.in
MIT License
4.83k stars 1.15k forks source link

Using table alias #134

Closed 2masbach closed 8 years ago

2masbach commented 10 years ago

I've seen in previous posts that the table alias is added to medoo, but I can't seem to find any documentation or guide on how to use the feature?

I've tried with the basic alias (as with columns) but this does not seem to work. Any directions?

quentinwalter commented 9 years ago

I have the same problem. Did you find out how to use this feature?

2masbach commented 9 years ago

Hi, by using (newname) in the end of the select statement, you can use aliases. My query: db->select( 'achievements', [ 'achievements.id(rankID)', 'achievements.rank' ], [ 'AND' => [ 'achievements.type' => 'match', 'achievements.active' => 1 ], ] ); the (rankID) creates the alias for use.

quentinwalter commented 9 years ago

Thank you for your answer. I already use aliases for the column names but I was wondering if it was possible to use them for the joined tables (see INNER JOIN item a_item):

SELECT a_item_id, a_item.name AS a_item_name, b_item_id, b_item.name AS b_item_name, type_id
FROM relation
INNER JOIN item a_item ON a_item.item_id = a_item_id
INNER JOIN item b_item ON b_item.item_id = b_item_id
WHERE a_item_id = 1 OR b_item_id = 1

I checked the regexp in the medoo class and I think this feature is not implemented yet. I use the method query instead.