i have the following sql query
SELECT id,
title,
total_likes,
IFNULL(SELECT 1 FROM 'likedata' WHERE user_id=$UID AND post_id=posts.id)0) AS is_liked
FROM 'posts'
I want to create mysql function to make my query bit shorter,
i don't know how to wrap the second query into sql function and pass 2 variables ($UID and $PID) to function to make this query shorter and more understandable.
any help would be great, thanks in advance