Solved

COMBINE TWO QUERIES

Posted on 2008-10-16
2
208 Views
Last Modified: 2012-05-05
Does anyone know why I can run this queries?

SELECT "Student ID", "Student Name" FROM "STUDENT DATA"
WHERE "Crs No" = 10 UNION ALL SELECT * FROM RVM9525.course WHERE  
courseNo = 10

It's giving error massage: query block has incorrect number of result columns
0
Comment
Question by:Dhehien
2 Comments
 
LVL 74

Accepted Solution

by:
sdstuber earned 250 total points
ID: 22733774
RVM9525.course must have more than 2 columns

you are querying 2 columns from the first table
but you are unioning it to an unknown number of columns in the second table.
0
 
LVL 143

Assisted Solution

by:Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3] earned 250 total points
ID: 22733778
SELECT *

is returning more that 2 columns!
either change the * into 2 columns, or add some dummy (null) values in the first part

note: SELECT * should really not be used in UNION queries...
0

Featured Post

Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
SQL Server 2012 r2 - Sum totals 2 28
T-SQL Default value in Select? 5 38
Complex Query - help please 5 52
SSRS: Why is Visual Studio stripping these properties? 2 21
Confronted with some SQL you don't know can be a daunting task. It can be even more daunting if that SQL carries some of the old secret codes used in the Ye Olde query syntax, such as: (+)     as used in Oracle;     *=     =*    as used in Sybase …
Composite queries are used to retrieve the results from joining multiple queries after applying any filters. UNION, INTERSECT, MINUS, and UNION ALL are some of the operators used to get certain desired results.​
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question