how can you query the database to perform this function?

this will have to go through every like in the system, which will result in some scalability problems