In a part of my sql query at 开发者_JS百科the end of the query I have this
GROUP BY
`Record`.`RecordID`
ORDER BY
`Record`.`RecordID`
it works fine until I have RecordID null, and then mysql query fails. Is there a way around that IFNULL I dont use GROUP BY and Order BY
thank
You can try:
GROUP BY IFNULL(`Record`.`RecordID`,0)
You can skip the ORDER BY
, since by default MySql will sort based on the GROUP BY
When you say fail, what do you mean?
If I have the table:
Value
a
b
{null}
c
c
and I run the query:
select value from table
group by value
Your result is:
{null}
a
b
c
To get rid of the nulls:
select value from table
group by value
having value is not null
I don't see how the GROUP BY and ORDER BY clauses in and of themselves can cause anything to fail. Please don't show just some part that you think is broken, if you knew better, you wouldn't need to ask here right?
Add a IS NOT NULL filter to remove them entirely
WHERE `Record`.`RecordID` is not null
GROUP BY
`Record`.`RecordID`
ORDER BY
`Record`.`RecordID`
精彩评论