473,396 Members | 1,847 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Query Error when trying to join 2 tables and group by a field

I may be going about this incorrectly but I thought I was doing the right thing. I have 2 tables with the same coulms. The data in each is identicle but each has columns will no data. So I want to combine the tables so that the missing data fills in. So I created a union query with a 'group by' expression. The union query works if I don't include the group expression. But the group expression returns an error that says, "You tried to execute a query that does not include the specific expression 'Issue' as part of an aggregate function. I'm not sure what I'm doing wrong. Here is my query:

Expand|Select|Wrap|Line Numbers
  1. SELECT SheetNumber, Issue, ProjectName, Discipline, Description, SheetSize, FileName
  2. FROM ProjectList
  3. UNION SELECT SheetNumber, Issue, ProjectName, Discipline, Description, SheetSize, FileName
  4. FROM PartialProjectList
  5. GROUP BY SheetNumber;
Oct 21 '10 #1
3 1199
dsatino
393 256MB
I think you have a misconception regarding what UNION query will do for you. A UNION will simply 'stack' (for lack of a better term) the results of one query on another.

You won't be able to fill in the missing data using this method because the 'missing' data is NULL and you won't be able to group NULL data with non-NULL data.
Oct 21 '10 #2
NeoPa
32,556 Expert Mod 16PB
The UNION aspect is irrelevant here. DSatino explains what UNION does quite well, but it's not related to this problem.

The problem is that whenever GROUP BY is used in a query the SELECT clause can only be made up of :
  1. Either items in the GROUP BY clause
  2. or items that are aggregated (Sum(), Count(), etc)
It is logically nonsense to ask for items that are not grouped and not aggregated as there is no possible way that it could determine which value you were after.

Consider the following data (in a table [Table1]) :
Expand|Select|Wrap|Line Numbers
  1. Field1  Field2
  2.  AAA       1
  3.  AAA       2
  4.  AAA       3
  5.  BBB       7
  6.  BBB       9
If the SQL said :
Expand|Select|Wrap|Line Numbers
  1. SELECT   [Field1]
  2.        , [Field2]
  3. FROM     [Table1]
  4. GROUP BY [Field1]
How could the server grant the request? What value to return for [Field2] across the three records where [Field1] = "AAA"?

The SELECT clause would need to be something like :
Expand|Select|Wrap|Line Numbers
  1. SELECT   [Field1]
  2.        , Sum([Field2]) As SumofField2
Oct 21 '10 #3
dsatino
393 256MB
That too.

I think what we're both trying to say is you need to do a little research on SQL in general.
Oct 21 '10 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Debbie | last post by:
Hi I have developed an application that access an SQL database and installed it on a different machine The installation is successful but when I try to run the application I get the following...
1
by: Jeff Thur | last post by:
I am getting this error when trying to run a stored procedure: Microsoft.VisualBasic.CompilerServices.LateBinding.LateInd exGet(Object o, Object args, String paramnames) +1361...
1
by: Ghanashyam | last post by:
Dotnet Framework 1.1 is installed on my computer running on Windows 2000 Professional.Visual Studio >net 2003 is installed.When I try to create an ASP.NET project I get following error. The web...
5
by: snicks | last post by:
I'm trying to exec a program external to my ASP.NET app using the following code. The external app is a VB.NET application. Dim sPPTOut As String sPPTOut = MDEPDirStr + sID + ".ppt" Dim p As...
1
by: dipesh | last post by:
I am getting error when trying to Add Web Reference in Visual Studio 2005. "Some of the files required for web references are not installed"
2
by: ticars | last post by:
I'm getting a weird error when trying to access a user control from within a base page during runtime. Here's what I have: I have a master page with a user control on it. I then have a few...
3
by: LRI41 | last post by:
I googled an error message and it came up with two posts on your forum and when I got there it said I needed to register to post my question, I am not sure whether is this the correct place to...
5
by: Martin | last post by:
I get below error when trying to write unicode xml to a zipfile. zip.writestr('content.xml', content.toxml()) File "/usr/lib/python2.4/zipfile.py", line 460, in writestr zinfo.CRC =...
1
by: jonny | last post by:
Went from using Visual Web Develop express to Visual Studio 2005 and getting error when trying to open project. Error message: "One or more projects in the solution could not be loaded for the...
1
by: hbsnam | last post by:
Getting following error when trying to add / submit a listing Warning: in_array() : Wrong datatype for second argument in /home/namibiac/public_html/addlisting.php on line 175 Warning:...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.