Request for a sample of two tables with a condition



  • There's a request.

    select
      `works`.*, count(`like`.`wid`) as likes
    from
      `works`, `like`
    where
     `works`.`id` = `like`.`wid`
    group by id
    

    and accordingly I get the data `works`.`id` = `like`.`wid`And how am I supposed to make it if it's in the table? like No record of where `works`.`id` = `like`.`wid`count(`like`.`wid`) as likes 0



  • Just use it. left join

    select `works`.*, count(`like`.`wid`) as likes 
        from `works` 
            left join `like` on `works`.`id` = `like`.`wid` 
        group by id
    

Log in to reply
 


Suggested Topics