简体   繁体   中英

Can´t figure out the problem with MYSQL query

Hey Guys I have this query

SELECT SUM(body), SUM(mice), SUM(sety) FROM
(
  SELECT sum(body1) as body, sum(mice1) as mice, sum(sety1) as sety from utkani where hrac1 in(select hrac1 from skupina where id=66) 
  UNION ALL
  SELECT sum(body2) as body, sum(mice2) as mice, sum(sety2) as sety from utkani where hrac2 in(select hrac1 from skupina where id=66) 
)

and I am getting error:

#1248 - Every derived table must have its own alias

Can you help me with this please?

A deivd table is that what youi have afuter the first FROM clause

As it is a tbale, it must a name like utkani but as you see a t1 is enough

SELECT SUM(body), SUM(mice), SUM(sety) FROM
(
  SELECT sum(body1) as body, sum(mice1) as mice, sum(sety1) as sety from utkani where hrac1 in(select hrac1 from skupina where id=66) 
  UNION ALL
  SELECT sum(body2) as body, sum(mice2) as mice, sum(sety2) as sety from utkani where hrac2 in(select hrac1 from skupina where id=66) 
) t1

I think you missed adding an alias to the virtual table you are querying

SELECT SUM(body), SUM(mice), SUM(sety) FROM
(
  SELECT sum(body1) as body, sum(mice1) as mice, sum(sety1) as sety from utkani where hrac1 in(select hrac1 from skupina where id=66) 
  UNION ALL
  SELECT sum(body2) as body, sum(mice2) as mice, sum(sety2) as sety from utkani where hrac2 in(select hrac1 from skupina where id=66) 
) as temp

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM