Questions tagged [mysql-error-1248]

error: #1248 - Every derived table must have its own alias

As the error says, in a MySql query you have to name every derived table.

Derived tables (often called subqueries) are result sets used as table sources in a query, like the one in the following example:

(SELECT MAX(id) FROM yourtable GROUP BY name)

and you have to give each derived table an alias:

(SELECT MAX(id) FROM yourtable GROUP BY name) AS max_id

(the AS clause is optional) and you can then use it, for example, this way:

SELECT yourtable.*
FROM
  yourtable INNER JOIN
  (SELECT MAX(id) max_id FROM yourtable GROUP BY name) max_ids
  ON yourtable.id = max_ids.max_id
17 questions
492
votes
4 answers

What is the error "Every derived table must have its own alias" in MySQL?

I am running this query on MySQL SELECT ID FROM ( SELECT ID, msisdn FROM ( SELECT * FROM TT2 ) ); and it is giving this error: Every derived table must have its own alias. What's causing this error?
silverkid
  • 9,291
  • 22
  • 66
  • 92
16
votes
3 answers

MYSQL ERROR 1248 (42000): Every derived table must have its own alias

I cant for the life of me figure out why this is erroring SELECT * FROM SELECT c.city_id, p.prop_ynow_id, p.propertyid, p.prop_add_value, p.name, picture, ifnull(p.address,'') as`location`, ifnull(city,'')as`city`, ifnull(ShortCut,'') as…
Matt Elhotiby
  • 43,028
  • 85
  • 218
  • 321
1
vote
3 answers

SQL statement error

mysql> Select Emp_B AS Total -> From (Select Sum(mines.NoOfWorkers) AS Emp_B from mines); ERROR 1248 (42000): Every derived table must have its own alias mysql> Select Emp_B AS Total -> From (Select Sum(mines.NoOfWorkers) from mines) AS…
Shawn
  • 11
  • 1
1
vote
1 answer

Subquery on a join

I'm trying to do a query to filter on rows from one table and then join the results on another table and then filter out additional rows. Here is the query I've written: SELECT * FROM (SELECT media.id AS id2, media.flagged AS flagged2,…
Eric
  • 138
  • 1
  • 10
1
vote
2 answers

Error 1248 in mysql

I am trying to run this query. select * from (select * from student where dept_name= ’Comp. Sci’) natural left outer join (select * from takes where semester = ’Spring’ and year = 2009); But every time i get…
Usman Tariq
  • 159
  • 1
  • 8
0
votes
2 answers

every derived table must have its own alias-can't find the error

select a.author_id,a.name,a.city,a.country from author a,catalog c where c.author_id=a.author_id and c.book_id=(select book_id from order_details group by book_id having sum(quantity)=(select max(quantity) from (select sum(quantity) as quantity…
0
votes
1 answer

join count from the same table

I need to query a table for some amounts Billed, Received, Adjusted but need to join into the table also a count of the samples that where serviced I could request this separately, but I would like to have the result nicely in one array This is the…
0
votes
3 answers

MySQL: Query to obtain recipes using all given ingredients

I have the following simplified tables: CREATE TABLE recipe(id int, name varchar(25)); CREATE TABLE ingredient(name varchar(25)); CREATE TABLE uses_ingredient(recipe_id int, name varchar(25)); I want to make a query that returns all id's of…
John_A
  • 1
  • 1
0
votes
2 answers

mySQL update question

Hey all i im getting this error when trying to update a table in my database: Every derived table must have its own alias Here is my mysql query i am trying to update with: UPDATE (SELECT clientinfo.idNumber, clientinfo.theCompName,…
StealthRT
  • 10,108
  • 40
  • 183
  • 342
0
votes
0 answers

MySQL error 1248: Every derived table must have its own alias

I run into this issue with the query SELECT GROUP_CONCAT( CONCAT( id , '|' , calc_eu , '|' , ( SELECT CASE WHEN texto IS NULL THEN '' ELSE texto END FROM ( …
Sir.Costy
  • 3
  • 3
0
votes
3 answers

MySql: Query multiple identical dynamic tables

I have a database with 500+ tables, each with identical structure, that contain historical data from sensors. I am trying to come up with a query that will locate, for example, all instances where sensor n exceeds x. The problem is that the tables…
JYelton
  • 35,664
  • 27
  • 132
  • 191
0
votes
1 answer

mysql error code 1248

I am getting an error code 1248 and have no idea why. Thanks in advance. select substr(cbt,1,8) day, max((delta_GTP_InDataPktGn+delta_GTP_OutDataPktGn))/900 from ( select a.cbt, a.datetime, a.GTP_InDataPktGn - b.GTP_InDataPktGn as…
il-fox
  • 75
  • 2
  • 8
0
votes
1 answer

Single select statement error "Every derived table must have its own alias"

I've been trying to get the following select statement to work for a few days now but haven't had any luck. A quick summary of the code is that it returns a list of all teams in the database and how many wins each team has against teams ranked in…
Jeremy
  • 1
  • 1
0
votes
1 answer

Unable to perform union, getting #1248 - Every derived table must have its own alias error

I have these two queries select t . *, events.event_time as last_time from events, ( ( select bonding.type, bonding.global_id2 as target_post, bonding.target_id as on_whose_post, …
Manish
  • 1,946
  • 2
  • 24
  • 36
0
votes
1 answer

Getting Error - Every derived table must have its own alias error

The query is to get the dates for each table, I have Checked my code but it still error's "Every derived table must have its own alias error" SELECT T.* FROM ( SELECT DISTINCT(DATE_FORMAT(p.deliverDate, '%M')) as PDate FROM piglet_po…
1
2