Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

mysql

How would I correct this error by setting an alias? error: #1248 - Every derived table must have its own alias

SELECT 
    entry_id,
    author_id,
    title,
    status
FROM exp_channel_titles

LEFT JOIN
(SELECT
    entry_id, 
    field_id_14,
    field_id_15,
    field_id_25,
    field_id_27, 
    field_id_28, 
    field_id_29, 
    field_id_30,
    field_id_31,
    field_id_32,
    field_id_33,
    field_id_34,
    field_id_35
FROM exp_channel_data
WHERE entry_id = exp_channel_titles.entry_id)

LEFT JOIN
(SELECT   
    member_id,
    email
FROM exp_members
WHERE member_id = exp_channel_titles.author_id)

WHERE title LIKE %Member% 
AND status = 'complete'
like image 239
acctman Avatar asked May 08 '12 08:05

acctman


People also ask

What is MySQL error?

Lost connection to MySQL server Network conditions should be checked if this is a frequent error. If an error message like “Lost connection to MySQL server” appears while querying the database, it is certain that the error has occurred because of network connection issues.

How do I find MySQL errors?

On Ubuntu systems, the default location for the MySQL is /var/log/mysql/error. log . In many cases, the error logs are most easily read with the less program, a command line utility that allows you to view files but not edit them: sudo less /var/log/mysql/error.

Why MySQL is not working?

normally means that there is no MySQL server running on the system or that you are using an incorrect Unix socket file name or TCP/IP port number when trying to connect to the server. You should also check that the TCP/IP port you are using has not been blocked by a firewall or port blocking service.


2 Answers

Well, as the error says, you have to name every derived table. For instance

(SELECT   
    member_id,
    email
FROM exp_members
WHERE member_id = exp_channel_titles.author_id)

Is a derived table. Add a name like so:

(SELECT   
    member_id,
    email
FROM exp_members
WHERE member_id = exp_channel_titles.author_id) tempTableNameGoesHere

(I think I'm sure there is no need for an as between the bracket and the name, but I suppose you can try it, or look it up from here ;) )

Your follow-up question (how long are we going to do this? :) )

 WHERE title LIKE %Member% 

should be

WHERE title LIKE '%Member%'
like image 99
Nanne Avatar answered Sep 21 '22 22:09

Nanne


SELECT 
    ect.entry_id,
    ect.author_id,
    ect.title,
    ect.status
FROM exp_channel_titles as ect

LEFT JOIN
(SELECT
    entry_id, 
    field_id_14,
    field_id_15,
    field_id_25,
    field_id_27, 
    field_id_28, 
    field_id_29, 
    field_id_30,
    field_id_31,
    field_id_32,
    field_id_33,
    field_id_34,
    field_id_35
FROM exp_channel_data) as ecd 
ON ecd.entry_id = ect.entry_id

LEFT JOIN
(SELECT   
    member_id,
    email
FROM exp_members) as exm
ON exm.member_id = ect.author_id

WHERE ect.title LIKE '%Member%' 
AND ect.status = 'complete'
like image 31
Imdad Avatar answered Sep 18 '22 22:09

Imdad