-
August 9th, 2010, 08:41 AM
#1
Help convert this query from oracle to mysql
Below is a valid oracle query, which is used to insert things into my database. I need to know the equivalent mysql query.
Code:
insert into SWAP_TABLE
select '123' prefix, ptgid, stgid from
(select GROUP_ID ptgid from ALL_GROUPS where label = 'foo'),
(select GROUP_ID stgid from ALL_GROUPS where label = 'bar')
union all
select '456' prefix, ptgid, stgid from
(select GROUP_ID ptgid from ALL_GROUPS where label = 'hello'),
(select GROUP_ID stgid from ALL_GROUPS where label = 'world')
I'm a software engineer so I don't really know much about DB queries. I had an oracle expert help me create this one, but he doesn't know mysql all that well.
The query is actually generated by code, the labels and prefixs can be anything and there might theoretically be hundreds of thousands of union alls in there.
-
August 11th, 2010, 04:34 AM
#2
Re: Help convert this query from oracle to mysql
The query looks like simple generic SQL syntax, so have you tried if it works in MySQL? And if not, which error do you receive?
-
August 11th, 2010, 09:47 AM
#3
Re: Help convert this query from oracle to mysql
Of course I tried it :P
Error #1248 - Every derived table must have it's own alias.
I don't know what that means, each one does have it's own alias.
-
August 13th, 2010, 07:53 AM
#4
Re: Help convert this query from oracle to mysql
The reason I asked was because I wanted the error message
Based on the error message I'd suggest that the (SELECT .... ) subqueries must have their own alias, something like
Code:
insert into SWAP_TABLE
select '123' prefix, T1.ptgid, T2.stgid from
(select GROUP_ID ptgid from ALL_GROUPS where label = 'foo') T1,
(select GROUP_ID stgid from ALL_GROUPS where label = 'bar') T2
union all
select '456' prefix, T3.ptgid, T4.stgid from
(select GROUP_ID ptgid from ALL_GROUPS where label = 'hello') T3,
(select GROUP_ID stgid from ALL_GROUPS where label = 'world') T4
Or something similar.
I don't know where the "prefix" comes from, so I don't know if that needs to be qualified.
Note this is just "guessing" right now, as I've not tested it in a MySQL but the error message indicates this.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|