#
#
# artur #2020-05-18 14:50:47
MySQL
# artur #, 2020-05-18 14:50:47

How to add value from 1st table with MIN value from 2nd table?

Hello.
Need help making a request.

It is necessary to get the sum of values ​​​​from 2 tables, a number is taken from the 1st table, the minimum number is selected from the 2nd table using MIN (). Can't add them up (

...or how to replace the NULL values ​​in the 1st table with the MIN() values ​​from the 2nd table?

Now we have the following:

$query = DB::select(
  array('items.id', 'id'),
 'items.price',
 'items.new_price', 
  array(DB::expr('MIN(items_variations.price)'), 'variation_price'), 
  array(DB::expr('MIN(items_variations.new_price)'), 'variation_new_price')
->from('items')
->join('items_variations', 'LEFT')
->on('items.id', '=', 'items_variations.item_id')


The task is to select the minimum item_id amount from the items_variations table and set the price, but only if price = NULL

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question