MySQL Join AND EXISTS in combination -


case got following query:

select * `parking_parking` join `parking_address` on `parking_parking`.`parking_address` = `parking_address`.`address_id` `parking_id` = 3 

this query selects information parking (address , data parking itself)

and in general.. works!

problem

there small problem though.. whenever address has been deleted database , parking still exists. entire query returns 0. because looks , a , b linked. if 1 not found second won't returned either.

now there solution.. exists

however not know how use it.

i tried:

exists join   join exists   join `parking_address` on exists 

but no avail.

i hope (and guess) have overlooked small thing.

note

!! not use in real life! !!

select * 

i did 1 when still @ veeeery basics , found out hard way simplest pages took ages load.

solution : goleztrol

select * `parking_parking` left join `parking_address` on `parking_parking`.`parking_address` = `parking_address`.`address_id` `parking_id` = 3 

change join (which short inner join) left join (= left outer join). return parkings , return null address fields if there no matching address:

select * `parking_parking` left join `parking_address`    on `parking_parking`.`parking_address` = `parking_address`.`address_id` `parking_id` = 3 

Comments

Popular posts from this blog

qt - Using float or double for own QML classes -

Create Outlook appointment via C# .Net -

ios - Swift Array Resetting Itself -