mysql - Count in query ruin expected result -


database structure

database structure

data

data

without count in query:

select id, test order asc limit 1  

good result: without count

with count in query:

select id, a, count(*) test order asc limit 1  

bad result: with count

why happening? alternative?

try

select id, a,  (select count(*) test) cnt  test order asc limit 1  

it should give expected results. though i'm pretty sure optimizer execute subquery once, makes sense check execution plan explain .


Comments

Popular posts from this blog

java - SSE Emitter : Manage timeouts and complete() -

jquery - uncaught exception: DataTables Editor - remote hosting of code not allowed -

java - How to resolve error - package com.squareup.okhttp3 doesn't exist? -