mysql - User defined variables does not work on where clause -


set @a:=0 

the below query works

select *,@a:=@a+1 article @a<=3 

this query returns 3 rows when query contains left join not work, returns rows.

select a.*,@a:=@a+1 article left join comments c on c.aid=a.id @a<=3 

i don't understand why query returns rows

limit 3 clearer expression of (it looks like) trying do. said, have been known borderline abuse session variables, , tend balk @ seeing them in clauses; inadvisable cross clauses them.

....though work you:

select a.*,@a:=@a+1 theavalue article left join comments c on c.aid=a.id having theavalue <=3 ; 

having processed after result fields have been calculated.


Comments

Popular posts from this blog

javascript - Karma not able to start PhantomJS on Windows - Error: spawn UNKNOWN -

c# - Display ASPX Popup control in RowDeleteing Event (ASPX Gridview) -

Nuget pack csproj using nuspec -