There is a mysql query:

mysql_query(" SELECT * FROM notifications INNER JOIN users u1 ON u1.vk_id = notifications.from INNER JOIN users u2 ON u2.vk_id = notifications.to WHERE notifications.npoints > 0 AND notifications.history = 1 AND (notifications.to = 1 OR notifications.from = 1) ORDER BY notifications.id DESC LIMIT 5 "); 

Does not respond to this line. Always pays attention only to from. Although it is written: to or from:

 notifications.to = 1 OR notifications.from = 1 
  • And specifically? Give sample data and sample data. Do you have a task for a condition? - Chad
  • @ Chad, why do you need it? I just need the correct condition. - ModaL
  • To understand what is wrong with you. Or do you really think MySQL is doing something wrong? Most likely you have a discrepancy in the understanding of the problem with its implementation. Although in principle I was on the drum. Not my request does not work :-) - Chad
  • And that means "does not react." users.vk_id = 1 is selected only once? Or what? Or maybe screened entries do not satisfy other conditions? - alexlz

2 answers 2

Try, and for the future, to use reserved words as field names to frame them with the symbol в вашем случае notifications . from`

 mysql_query(" SELECT * FROM `notifications` INNER JOIN `users` u1 ON u1.`vk_id` = `notifications`.`from` INNER JOIN `users` u2 ON u2.`vk_id` = `notifications`.`to` WHERE `notifications`.`npoints` > 0 AND `notifications`.`history` = 1 AND (`notifications`.`to` = 1 OR `notifications`.`from` = 1) ORDER BY `notifications`.`id` DESC LIMIT 5 "); 

    it's not at all clear why an inner join is here? With such search criteria, they are not needed.

    Maybe you need to check:

    .. AND (u1.vk_id = 1 OR u2.vk_id = 1) ?

    Are you sure that with to = 1 notifications.npoints> 0 and notifications.history = 1?

    • Regarding the terms of the request - absolutely one-handedly. And joining must be apparently to rip data on users - Chad
    • hmm, part of the message is missing. Are you sure that with to = 1 notifications.npoints> 0 and notifications.history = 1? - Alex Kapustin
    • @shurik, yes, sure. And why are you again about to? He has to either to or from. - ModaL