1

I am using this class

$resource = \Magento\Framework\App\ResourceConnection;
connection = $resource->getConnection();

to get data from some custom tables using a JOIN

$select = $block->connection->select()
    ->from(['table1' => $this->getTable('table1')])
    ->join( ['table2' => 'table2'],
        'table1.id = table2.package_group_id')
    ->join(['table3' => 'table3'],
        'table2.isbn = table3.sku')
    ->where('table1.custom_site_url_key =?',$school_key_url);

This is returning all the columns but I just want one column from table 1 and another from table 3. Someone know how can I get just the necessary columns?

Thanks

1
  • You can echo $select and debug the query in mysql, then only you will get to know that it has one records or multi-records and also there is an issue with magento select function or your query that you have passed in select function.
    – Nits
    Commented Jul 28, 2022 at 6:09

1 Answer 1

1

You can specify needed columns in the second argument of from clause:

->from(
    ['table1' => $this->getTable('table1')],
    ['table1.columnA', 'table3.columnB']
)

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.