I'm triying to get ALL posts and a variable "liked" next to the post to check if the user liked it or not.

I have three table with theses :

**-posts**

```
+----+---------+---------+
| id | user_id |   text  |
+----+---------+---------+

```

**-votes**

```
+----+-----------+---------+---------+
| id | type_vote | user_id | post_id |
+----+-----------+---------+---------+

```

**-users**

```
+---------+---------+
| id_user | etc..   |
+---------+---------+

```

I check the others answers but it don't solve my problem. Also I tried this code :

```
SELECT id, text,
            IF('$uid' IN (SELECT id FROM votes WHERE user_id='$uid'), 1, 0) AS liked
            FROM posts
            INNER JOIN users
            ON users.id_user = posts.user_id
            WHERE posts.user_id = '$uid' OR posts.user_id 
        ORDER BY posts.created_at desc

```

But it returns only posts created by user and the liked variable doesn't work..

What am I missing?

Thanks in advance !

**EDIT :** 

I managed to get the id of the votes next to the appropriate post, how to transform it in 0 if NULL and 1 if id exists ?

```
SELECT p.*,(SELECT id from votes where user_id = '$uid' AND post_id = p.id) as liked from posts p

```

I get a result like :

```
    +----+------+---------+---------------+
    | id | text | user_id |liked          |
    +----+------+---------+-----+---------+
    | 1  | blab | 5476zef |NULL OR post_id|
    +----+------+---------+---------------+

```