Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Derby Select over subquery not working

Does Derby not allow you to select over the returned relation of another query?

For example, this query works fine:

SELECT * 
FROM users, stats 
WHERE users.uid = stats.uid;

but this query returns an error:

SELECT username, hits 
FROM (
  SELECT * 
  FROM users, stats 
  WHERE users.uid = stats.uid
);

The error reads:

Error: Syntax error: Encountered "<EOF>" at line 1, column 83.
SQLState:  42X01
ErrorCode: 30000

I am used to Oracle where this works fine.

The above query is just an example, I know I can select username, hits originally without the need for a nested query.

like image 294
c_breeez Avatar asked Jul 28 '14 16:07

c_breeez


1 Answers

As mentioned by xQbert above, Derby requires you to alias tables in an inline query.

The solution to the question is to do this:

SELECT username, hits 
FROM (
  SELECT * 
  FROM users, stats 
  WHERE users.uid = stats.uid
) AS tmp;

Thanks for the help xQbert

like image 123
c_breeez Avatar answered Oct 05 '22 12:10

c_breeez