mysql - Every Derived Table must have it's own alias -


here mysql syntax:

select f1.id   (select f1.id,           count(*) c1    (friend f1          join friend f2 on (f1.fid=f2.fid                                , f1.id!=f2.id                                , f2.id=12345                                , f1.id!=12345))) c1>=     (select count(*)      friend f3      f3.id=12345); 

i can't seem figure out where's problem, tried aliasing inner result tables seem return error! need guidelines.

get rid of extraneous parenthesis , format query bit have cleaner look:

select t.id  (select f1.id,count(*) c1        friend f1        join friend f2          on  f1.fid=f2.fid ,               f1.id!=f2.id ,               f2.id=12345 ,               f1.id!=12345) t -- <-- alias needed here! c1>=(select count(*) friend f3 f3.id=12345) 

if format above, you'll realize derived table of query missing alias.

also, field selected outermost query, i.e. id should prefixed using alias of derived table, i.e. t.


Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -