Mysql Sql Error 1248
Contents |
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this
Mysql Error Code 1248 Every Derived Table Must Have Its Own Alias
site About Us Learn more about Stack Overflow the company Business Learn more mysql derived table about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x
Mysql Union
Dismiss Join the Stack Overflow Community Stack Overflow is a community of 6.2 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up mySQL error: mysql group by #1248 - Every derived table must have its own alias up vote 6 down vote favorite 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 mysql join = 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' mysql share|improve this question asked May 8 '12 at 8:45 acctman 1,9022070107 add a comment| 3 Answers 3 active oldest votes up vote 14 down vote 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%' share|improve this answer edited May 8 '12 at 9:13 answered May 8 '12 at 8:48 Nanne 46.5k1376112 (this goes for all derived tables ofcourse, not just for this one) –Nanne May 8 '12 at 8:48 thanks ... now i'm getting another er
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 6.2 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up How to solve ERROR 1248 (42000): Every derived table must have its own alias up vote 0 down vote favorite The following query gives me ERROR 1248 (42000): Every derived table must have its own alias SELECT * FROM post LEFT JOIN post_plus ON ( post.id = http://stackoverflow.com/questions/10495373/mysql-error-1248-every-derived-table-must-have-its-own-alias post_plus.news_id ) LEFT JOIN (SELECT DISTINCT c1.postid FROM post_category c1 JOIN post_category c2 ON c1.postid = c2.postid WHERE c1.categoryid IN ( 130, 3, 4, 5 ) AND c2.categoryid = 73 ) where approve = 1 ORDER BY fixed DESC, date DESC LIMIT 0, 7; what i've tried SELECT a.* (FROM post ... LIMIT 0, 7)a; mysql sql share|improve this question edited Sep 8 '13 at 20:28 asked Sep 8 '13 at 20:21 user2696962 143312 1 the subquery in the second LEFT JOIN does not have http://stackoverflow.com/questions/18688283/how-to-solve-error-1248-42000-every-derived-table-must-have-its-own-alias an alias. –John Woo Sep 8 '13 at 20:23 add a comment| 1 Answer 1 active oldest votes up vote 3 down vote accepted The derived table needs an alias and you were missing a join condition onto it as well. SELECT * FROM post LEFT JOIN post_plus ON ( post.id = post_plus.news_id ) LEFT JOIN (SELECT DISTINCT c1.postid FROM post_category c1 JOIN post_category c2 ON c1.postid = c2.postid WHERE c1.categoryid IN ( 130, 3, 4, 5 ) AND c2.categoryid = 73) post_category /*<-- Missing Alias*/ ON ( post_category.postid = post.id ) /*<-- Missing Join Condition*/ WHERE approve = 1 ORDER BY fixed DESC, date DESC LIMIT 0, 7; share|improve this answer answered Sep 8 '13 at 20:25 Martin Smith 263k34416488 It's working but instead of selecting posts from a specific category it prints all posts. ignoring the SELECT DISTINCT... WHERE c1.categoryid IN ( 130, 3, 4, 5 ) AND c2.categoryid = 73 –user2696962 Sep 8 '13 at 21:17 1 @user2696962 - You need inner join not left join then. –Martin Smith Sep 8 '13 at 21:20 add a comment| Your Answer draft saved draft discarded Sign up or log in Sign up using Google Sign up using Facebook Sign up using Email and Password Post as a guest Name Email Post as a guest Name Email discard By posting your answer, you agree to the privacy policy and terms of service. Not the answer you're looking for? Browse other questions tagged mysql sql or ask your own question. asked 3 years ago vi
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about http://stackoverflow.com/questions/23316558/error-1248-every-derived-table-must-have-its-own-alias Stack Overflow the company Business Learn more about hiring developers or posting ads with http://stackoverflow.com/questions/1888779/every-derived-table-must-have-its-own-alias us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 6.2 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up Error #1248 - Every derived table must have its own alias [duplicate] up vote sql error 0 down vote favorite This question already has an answer here: every derived table must have its own alias 3 answers I'm getting the following error while running this query: Error #1248 - Every derived table must have its own alias SELECT free_from, free_until FROM ( SELECT a.end AS free_from, (SELECT MIN(c.start) FROM bookings c WHERE c.start>a.end) as free_until FROM bookings a WHERE NOT EXISTS ( SELECT 1 FROM bookings b mysql sql error WHERE b.start BETWEEN a.end AND a.end + INTERVAL your_duration HOURS ) AND a.end BETWEEN start_of_search_window AND end_of_search_window ) ORDER BY free_until-free_from LIMIT 0,3; mysql sql database share|improve this question edited Apr 26 '14 at 21:13 Abhik Chakraborty 37k41737 asked Apr 26 '14 at 21:12 Nitin Tolani 112 marked as duplicate by lanzz, Mike W, Aleks G, jaypal singh, ᴳᵁᴵᴰᴼ Apr 27 '14 at 2:28 This question was marked as an exact duplicate of an existing question. That's a messy query –Aleks G Apr 26 '14 at 21:15 this kind of question requires some data along with the table structure. –Abhik Chakraborty Apr 26 '14 at 21:26 add a comment| 1 Answer 1 active oldest votes up vote 0 down vote Every subquery in the from clause ("derived table" as MySQL calls them) needs to have a name. This is a table alias. If you format your queries so they are more readable, you can probably readily see where the alias is needed: SELECT free_from, free_until FROM (SELECT a.end AS free_from, (SELECT MIN(c.start) FROM bookings c WHERE c.start>a.end ) as free_until FROM bookings a WHERE NOT EXISTS (SELECT 1 FROM bookings b WHERE b.start BETWEEN a.end AND a.end + INTERVAL your_duration HOURS ) AND a.end BETW
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 6.2 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up every derived table must have its own alias up vote 194 down vote favorite 30 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 is wrong ? mysql mysql-error-1248 share|improve this question edited Jul 10 '12 at 18:57 Teun Zengerink 2,73941929 asked Dec 11 '09 at 15:24 silverkid 2,370165081 11 Couldn't you just simplify this as "select ID from TT2"? –DMKing Dec 11 '09 at 15:29 1 I got this error recently because I had an extra ) in a query with a lot of UNION ALLs. –mpen Feb 17 '12 at 0:52 9 Seeing as how this is the #1 Google search... The accepted answer doesn't really answer the error 'Every derived table must have its own alias'. Look below for more info. –Daniel B. Chapman Aug 30 '12 at 16:01 add a comment| 3 Answers 3 active oldest votes up vote 283 down vote accepted Every derived table (AKA sub-query) must indeed have an alias. I.e. each query in brackets must be given an alias (AS whatever), which can the be used to refer to it in the rest of the outer query. SELECT ID FROM ( SELECT ID, msisdn FROM ( SELECT * FROM TT2 ) AS T ) AS T In your case, of course, the entire query could be replaced with: SELECT ID FROM TT2 share|improve this answer