A
A
astorix20252018-03-12 13:51:02
PHP
astorix2025, 2018-03-12 13:51:02

How to output data using sql query?

Guys tell me, there are two tables, this is the table all_fruits and table2 my_fruits It is
necessary that if table 2 my_fruits has, for example, the fruit "Apple", then using a sql query, all fruits except the apple will be displayed, since I have it
I tried this SELECT * FROM my_fruits, all_fruits WHERE my_fruits.id!=all_fruits.id AND my_fruits.name = 'Sergey'
PS I can print if only one fruit is stored in the table my_fruits, if 2 or more fruits are stored, then it repeats several times when outputting the name of the same fruit

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
Nick Sdk, 2018-03-12
@astorix2025

SELECT *
FROM все_фрукты
WHERE NOT EXISTS (SELECT * FROM мои_фрукты WHERE все_фрукты.id=мои_фрукты.id AND мои_фрукты.имя='Сергей')

try variations
EXISTS
NOT EXISTS
look at the results

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question