1

Need help in mysql for selecting row there are any value is null. table design given

id      userid           left    right

8   yusuf1@gmail.com    yusuf1  yusuf4 
9   yusuf2@gmail.com    yusuf1  NULL    
10  yusuf4@gmail.com    NULL    NULL    
11  yusuf10@gamil.com   NULL    NULL    

Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, bool given in D:\xampp\htdocs\mlm\all\join.php on line 325

select * from tree where left is NULL or right is NULL limit 1

Error

SQL query: Documentation

select * from tree where left is NULL or right is NULL limit 1

MySQL said: Documentation

#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'is NULL or right is NULL limit 1' at line 1

Nigel Ren
  • 56,122
  • 11
  • 43
  • 55
  • Have you tried the query against just the DB, for example in PHPmyAdmin. This will tell you if it's indeed your SQL or something in your PHP code. In other words if it works in there, then its a PHP code issue, if not it's an easier place to figure out the issue. – ArtisticPhoenix Feb 05 '19 at 08:19
  • Your query has some problems, but it should be running without error. So, I blame your PHP code (which we can't even see right now). Tip of the day: `LIMIT` without `ORDER BY` is fairly meaningless, so you should add an `ORDER BY` clause to your query. – Tim Biegeleisen Feb 05 '19 at 08:20
  • You should tag MariaDB, i don't know if there are syntax differences, but that could be. About other comments, the error comes from the SQL request, it's clearly stated in the error, not PHP then – Kaddath Feb 05 '19 at 08:22
  • 1
    `left` and `right` are reserved words in MySQL – Nigel Ren Feb 05 '19 at 08:22
  • what does your `mysqli_fetch_array()` statement look like on line 325 of _join.php_? – tshimkus Feb 05 '19 at 08:25

0 Answers0