0

I have a query where i join a couple of tables. 2 tables contain the same fieldname, so i want to select 1 table AS another name. I know how to do that, but it seems that when i query a field AS another name, it selects only that field.

My question is: how can i select all fields in the table, and a particular field AS another name?

This is how i have my code at this moment:

    $select->from('one');
    $select->join('two', 'one.item_id = two.id', array('item_name' => 'name'));
    $select->join('three', 'one.item_id = three.item_id');

So i want to select all from two, and name the field name AS item_name.

Thanks in advance!

2
  • You should do it how it's supposed to be done: selecting EACH field you need. You're familiar with the subject "do not select *", I assume. Commented Mar 25, 2011 at 12:05
  • Well, have a LOT of fields and i have to select them all, so I was hoping for an easier way :( Can you explain why select * is bad practice? Thanks. Commented Mar 25, 2011 at 12:08

1 Answer 1

1

I haven't tried this but I think you're able to do this:

$select->join('two', 'one.item_id = two.id', array('item_name' => 'name', '*'));
Sign up to request clarification or add additional context in comments.

1 Comment

I see you edited my answer, that's fine, but both notations ('name as item_name' or 'item_name' => 'name') will work, in case someone is interested :-).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.