Saturday 15 March 2014

php - Why does my SQL statement return 1 even though both tables are empty? -


I have two table items and dialects. I want to connect with them and I want to select the highest bid for each item. As of now the table is empty and I want to make it so that when I do a mysqli_num_rows it returns to 0, but it returns 1. When it returns, I have to display the text, which says that there are no new items

  select i_name, i_id, MAX (value) use the Join Item bid (i_id)   

My questions are:

Why does it come back 1? Basically, it returns a line because you include the maximum (price) I , so the query will always return its value. If the table is empty, it will be zero, so that there is a row.

Every time you include an integrated function and there is no GROUP BY section in it, the result is a line.

It is easy to decide: Use the group BY section: select from i_name, i_id, MAX (price) items i_name, i_id Use of the Use Bid by group (i_id) group has no items and when there are no bids for existing items, then the lines give the line 0.

However, if you want to show the query unclaimed items and if there are no items, return only 0 rows, use a left zone:

     by SELECT i_name, I_id, MAX (value) items, join bid (i_id) group

No comments:

Post a Comment