B
B
Bjornie2017-02-14 01:03:57
MySQL
Bjornie, 2017-02-14 01:03:57

How to return successfully found values ​​if no other values ​​are found in the database?

For example, there is a request:

SELECT s1.id AS sq_id, s1.name AS t1_name, s2.id AS t2_id, s2.name AS t2_name 
FROM `list` AS s1 
INNER JOIN `list` AS s2 ON s2.name = "XXX"
WHERE s1.name = "YYY";

In this case, if XXX or YYY is not found, then a completely empty response is returned. How to make a query so that if one of the conditions is found, then return at least it? Thank you!

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
Rsa97, 2017-02-14
@Rsa97

MySQL OUTER JOIN is not supported. can be emulated via LEFT JOIN ... UNION ... RIGHT JOIN.
Isn't it easier to choose separately for XXX and separately for YYY?

N
nozzy, 2017-02-14
@nozzy

I do not understand why join is here?

SELECT s1.id AS sq_id, s1.name AS t1_name  
FROM `list` AS s1 
WHERE s1.name IN ("YYY", "XXX")

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question