I need help.
I have 2 tables with names bkeys ( id, bkey, ip, user_id )
and wp_usermeta
(yes, wordpress table, fields of interest are user_id
, meta_key and
meta_value
).
What I need is to select all rows from bkeys + value of meta_value where key is nickname, so result will have fields bkey, ip and meta_value.
The problem is, bkeys table can have NULL for ip and user_id (meaning keys is not taken by any user yet) so rows with NULL for user_id won’t be selected with query like
SELECT bkeys.bkey, bkeys.ip, wp_usermeta.meta_value
FROM bkeys
LEFT JOIN wp_usermeta ON ( bkeys.user_id = wp_usermeta.user_id )
WHERE meta_key='nickname'
what i need is that all rows are selected, even where user_id is null. Is it possible? If it is, how?
Try moving the
meta_key = 'nickname'
to theON
clause:Think about
LEFT JOIN
s as a two-phase filtering:ON
condition, else you join a NULLed rowWHERE
condition.