从两个表中选择变量

I have two tables:

comments: id, username, autorpost, comment, id_post, time

posts:  id, autorid, autor, date, longitude, latitude, title, text, town, time

Now I want to select only these rows of the table posts where the username, which I had saved in a cookie $username = $_COOKIE['username']; have the same value how the username in the table comments. Is that possible or should I add any columns?

"SELECT
    c.id,
    c.username,
    c.autorpost,
    c.comment,
    c.id_post,
    c.time,
    p.id,
    p.autorid,
    p.autor,
    p.date,
    p.longitude,
    p.latitude,
    p.title,p.text,p.town,p.time 
from comments c 
JOIN posts p 
on p.id=c.id_post 
where c.username='".$username."'";

Execute this query to get post of user stored in cookie.

select Post.* from posts as Post
Left Join
comments as Comment on Post.id = Comment.id_post
where
Comment.username = $_COOKIE['username'];

Hi use the following code snipped -

$query = "SELECT * FROM posts p
JOIN comments c ON p.id = c.id_post
WHERE c.username = '$username'"

$result = mysqli_query($link,$query);

while($row = mysqli_fetch_assco($result)){
    //Your code
}

Instead of * use the appropriate coloumns you want to access