T
T
The_XXI2020-11-05 03:04:07
MySQL
The_XXI, 2020-11-05 03:04:07

How to pull data from a table according to data from where of another table?

There is a request

select * from items where prise > (select sell_prise from results where items_id = 1) and id = 1;
.
How can I replace the first 1 with an appeal to the second?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
W
WStanley, 2020-11-05
@WStanley

you have written

SELECT *    # - выбрать все *(звездочка)
FROM items    # - из таблицы items
WHERE   # - где
prise >   # - цена prise больше(пишется price правильно) 
(			
   # Этот подзапрос вернет число которое сверяется с prise			
  SELECT sell_prise   # - выбрать sell_prise (sell_priсe правильно)
  FROM results    # - из таблицы results
  WHERE items_id = 1  # - где items_id (в таблице results) = 1
) 
AND id = 1;    # - и id (в таблице items ) = 1

What does it mean to replace the first with an appeal to the second?
.

S
Sergey Vodakov, 2020-11-05
@WaterSmith

SELECT *
FROM items LEFT JOIN results ON items.id = results.items_id
WHERE items.prise > results.sell_prise

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question