August 18, 2009 at 11:29 am
Hi Every body,
select * from aaa
insert into aaa
select (e.lastname as bbb, o.orderdate as cccc)
from employees e, orders o where e.employeeid=o.order id
executing this query it is giving this error
incorrect syntax the key word as plz help
August 18, 2009 at 11:31 am
Why do you have parentheses around the columns in the select statement?
- Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
Property of The Thread
"Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon
August 18, 2009 at 11:33 am
And why do you need column name aliases when you are just doing an insert? Remove the parentheses and aliases.
August 18, 2009 at 11:36 am
On the column aliases, I do that to keep track of which source column is going into which destination column. Of course, I write my inserts explictly instead of implictly, because of the issues on that, and in that case, if you have more than a couple of columns, it's helpful to alias them. For documentation purposes, I mean.
- Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
Property of The Thread
"Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon
August 18, 2009 at 11:39 am
you should also *really* avoid doing this:
"select (e.lastname as bbb, o.orderdate as cccc)
from employees e, orders o where e.employeeid=o.order id "
that sort of syntax is most likely going to be deprecated in future versions.
you should write it like this:
"select e.lastname as bbb, o.orderdate as cccc
from employees e
JOIN orders o ON e.employeeid=o.orderid"
that also allows you to more effectively write queries that involve both normal INNER JOINs as well as OUTER JOINs.
-- oh, small note, JOIN is equivalent to writing INNER JOIN, incase you're wondering.
August 18, 2009 at 11:51 am
GSquared (8/18/2009)
On the column aliases, I do that to keep track of which source column is going into which destination column. Of course, I write my inserts explictly instead of implictly, because of the issues on that, and in that case, if you have more than a couple of columns, it's helpful to alias them. For documentation purposes, I mean.
You won't believe but I read it initially as you saying "you can use aliases to alter sequence of columns when doing an implicit insert" and rushed ahead to test that I didn't know of this for so long. :blush:
August 18, 2009 at 12:09 pm
Hi Thank you replly
in that query i not selecting the date
I am inserting date one new date with differenct table (employee,orders)
so plz suggest me it gives same error
Thanks
August 18, 2009 at 12:20 pm
you're really going to have to provide more info if this query doesn't work, since we don't have anything to help you with.
insert into aaa
select e.lastname as bbb, o.orderdate as cccc
from employees e
join orders o on e.employeeid=o.order id
August 18, 2009 at 2:35 pm
rjv_rnjn (8/18/2009)
GSquared (8/18/2009)
On the column aliases, I do that to keep track of which source column is going into which destination column. Of course, I write my inserts explictly instead of implictly, because of the issues on that, and in that case, if you have more than a couple of columns, it's helpful to alias them. For documentation purposes, I mean.You won't believe but I read it initially as you saying "you can use aliases to alter sequence of columns when doing an implicit insert" and rushed ahead to test that I didn't know of this for so long. :blush:
I tend towards over-long sentences. Makes them a bit hard to parse. Considering that, it makes sense that it could be misread. (It almost hurts to write such short sentences. Not my usual style at all. 🙂 )
- Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
Property of The Thread
"Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon
August 18, 2009 at 2:36 pm
kumar99ms (8/18/2009)
Hi Thank you repllyin that query i not selecting the date
I am inserting date one new date with differenct table (employee,orders)
so plz suggest me it gives same error
Thanks
I don't understand this post.
The suggestion was to remove the parentheses from the select statement. They don't belong there. They are causing an error message. Remove them and that error will go away.
- Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
Property of The Thread
"Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon
Viewing 10 posts - 1 through 9 (of 9 total)
You must be logged in to reply to this topic. Login to reply