Go Back   The UNIX and Linux Forums > Top Forums > Programming


Programming Post questions about C, C++, Java, SQL, and other programming languages here.

Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 07-31-2012
Registered User
 
Join Date: Jul 2012
Location: chennai
Posts: 59
Thanks: 6
Thanked 0 Times in 0 Posts
Data Getting error in sql query

Hi All ,
I have tried many times am getting syntax error on 'UNION'
can anybody tell me ...

Code:
INSERT INTO table1
(
Type
, num_items
, num_letters
, total_value
)
(select
type='1',
num_items,
num_letters=count(*),
total_value=sum(letter_value)
from
table2
where
num_items = 1
group by
num_items)
UNION
( select
type='2',
num_items,
num_letters=count(*),
total_value=sum(letter_value)
from
table2
where
num_items = 2
group by
num_items)
UNION
( select
type='3',
num_items,
num_letters=count(*),
total_value=sum(letter_value)
from
table2
where
num_items = 3
group by
num_items) ;

Moderator's Comments:
Code tags for code please.

Last edited by Corona688; 07-31-2012 at 10:22 AM..
Sponsored Links
    #2  
Old 07-31-2012
Mead Rotor
 
Join Date: Aug 2005
Location: Saskatchewan
Posts: 16,591
Thanks: 501
Thanked 2,574 Times in 2,453 Posts
I don't think 'type=3' makes sense inside a select like that. I think you might be able to do '3 as type'.
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Shell Script to execute Oracle query taking input from a file to form query DevendraG Shell Programming and Scripting 2 11-10-2011 05:56 AM
Query a oracle DB when fail put in in the error log Roadster Shell Programming and Scripting 8 02-04-2011 06:27 AM
Query Oracle tables and return values to shell script that calls the query balaeswari Shell Programming and Scripting 6 02-04-2010 08:35 AM
error ORA-06512 while running query in script shivanete Shell Programming and Scripting 3 12-04-2008 06:45 AM
Patch query using shell script error a1_win Shell Programming and Scripting 1 10-09-2008 05:51 AM



All times are GMT -4. The time now is 08:51 PM.