Group by sql where statement error?

Group by sql where statement error?

There is some nasty error that you can get in this sql query.

The error should be something like this:

Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given in

The correct statement is this:

1
2
mysqli_query($connection, "SELECT * FROM table where id = 1 group by column_name order by id ASC LIMIT 50");
while {}

By default, you might think the statement is this:

2
SELECT * FROM table group by column_name where id = 1...

That will trigger an error.

The statement will only work if you don’t put any where clause.

To optimize, you can select only certain columns.

3
4
mysqli_query($connection, "SELECT column_name1, column_name2 FROM table where id = 1 group by column_name1 order by id ASC LIMIT 50");
while {}

If you have any questions, leave in the comments.

Add a comment: