You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When using a function around a field value which points to another table it usually creates a subquery, but where should the function go, around the field within the subquery, or around the subquery?
In most instances, Dare would create a subquery, so the query would look like...
SELECT name, (
SELECT IF(id, "YES", "NO")
FROM email
WHEREemail.member_id=members.idLIMIT1
)
FROM members
Notice how the IF(...) is within the Subquery itself.
However if there is are no matches in the joining table the result will be NULL not "NO" - because the subquery returned zero rows. It needs at-least one empty row so the IF condition can say "No".
What was really meant was...
SELECT name, IF((
SELECT id
FROM email
WHEREemail.member_id=members.idLIMIT1
), "YES", "NO")
FROM members
Of course some functions are aggregates like MAX, COUNT, GROUP_CONCAT, ... these will always need to be defined within the subquery to work. They even have the affect of aggregating the results of a query within mysql.
The text was updated successfully, but these errors were encountered:
When using a function around a field value which points to another table it usually creates a subquery, but where should the function go, around the field within the subquery, or around the subquery?
For example...
e.g.
In most instances, Dare would create a subquery, so the query would look like...
Notice how the
IF(...)
is within the Subquery itself.However if there is are no matches in the joining table the result will be
NULL
not"NO"
- because the subquery returned zero rows. It needs at-least one empty row so theIF
condition can say "No".What was really meant was...
Of course some functions are aggregates like
MAX, COUNT, GROUP_CONCAT, ...
these will always need to be defined within the subquery to work. They even have the affect of aggregating the results of a query within mysql.The text was updated successfully, but these errors were encountered: