473,657 Members | 2,300 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Query - Can a Union query solve this problem

1 New Member
Please I need help! How can i write a query the gives me this result below
Expand|Select|Wrap|Line Numbers
  1. Trans no Fund1    Per  Fund2   Per
  2. 2           1   10%    2      20%
From my base table that looks like this
Expand|Select|Wrap|Line Numbers
  1. Trans no   Funds  Per
  2. 2             1   10%
  3. 2             2   20%
Many thanks
Dapo
Jan 25 '13 #1
3 1177
Anas Mosaad
185 New Member
I don't believe you need a union. You need a join to implement this one -assuming that funds can be only 1 or 2. A query like this one would solve it for you:
Expand|Select|Wrap|Line Numbers
  1. select t1.Trans_no, t1.Fund, t1.Per, t2.Fund, t2.Per
  2. from (select Trans_no, Fund, Per from Trans where Fund = 1) t1 left outer join
  3.     (select Trans_no, Fund, Per from Trans where Fund = 2) t2 on t1.Trans_no = t2.Trans_no
  4.  
I didn't run the above query but it should give you some guidance on how to implement it.
Jan 25 '13 #2
zmbd
5,501 Recognized Expert Moderator Expert
Well Dee,
From the extremely small amount of data, I'm going to guess that your database isn't normalized:
A Tutorial for Access
Database Normalization and Table Structures.

I haven't taken a close look at Mosaad's SQL; however, it's missing a closing ";" and I don't see how it would provide the format you desire.

I'm on my way out the door (morings are so busy) to take kids to school; however, I hope to take a closer look in a few hours; however, it would appear to me that crosstab-query or a pivot-table would be somethings to take a look at for the solution.
Jan 25 '13 #3
NeoPa
32,568 Recognized Expert Moderator MVP
Access's Jet SQL doesn't fuss over semi-colons (;) Z. That said, it wouldn't (as far as I'm aware) recognise the "OUTER" part of "LEFT OUTER JOIN".

Fundamentally though, although this looks to fit a Cross-Tab query perfectly, the concept that Anas has outlined would also work perfectly well.
Jan 25 '13 #4

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

Similar topics

3
3556
by: Paradigm | last post by:
I am using Access 2K as a front end to a MYSQL database. I am trying to run a Union query on the MYSQL database. The query is (much simplified) SELECT as ID from faxdata UNION SELECT as ID from letdata UNION SELECT as ID FROM MEMODATA; I get an ODBC error. The same query runs when the backend files are MDB files and it runs with MYSQL if I only combine 2 tables.
0
3950
by: s_gregory | last post by:
The mdb is considerable size 70 +- mb. A complex union query was working well, but when an additional union select... was added into the query, selecting identical fields from a different source, it began to have problems. Failure was observed only in a few PC's at first. For example, in an NT 4.0 SP6 PC, it continued to work OK. But in my Win 2k laptop, it failed. As the union query was gradually simiplified in testing, the failure...
4
1930
by: Missy | last post by:
We’ve recently upgraded our computer system to XP. My union query (which was working perfectly for years) now returns hieroglyphics instead of invoice numbers. When I run the 2 queries separately (of which the Union query is made up of) they return numbers perfectly. Can you please help? The Union Query looks like this: SELECT * FROM UNION SELECT * FROM ;
0
1594
by: jimmyshaw83 | last post by:
I am sorry if this topic is tired, but after all that I have read I am still in the woods here. I have built a database to handle weekly and monthly reports of what people are doing. They submit what they are working on and then you input a date and the info is narrowed allowing a report to be created containing all of the memo fields submitted during those dates. My Source Query gets all the memo fields in their entirety (greater than...
2
4026
by: Lenin Torres | last post by:
Hi everybody I have an Union Query that works fine. I used this query as the RecordSource for a Form. That Form is used as a subform in another form. Everything works fine, except for the "Filter by form" feature. When the user tries to use Filter by form a messagebox is displayed: "There are too many controls in this form to perform a filter by form", after that,when the user exit the Filter by Form mode, Access crash, displaying a...
5
2279
by: BillCo | last post by:
I'm having a problem with a union query, two simple queries joined with a union statement. It's created in code based on parameters. Users were noticing some inconsistant data and when I analysed the query produced and opened it from a MS Query it started giving strange results. The first query when run alone returns 22 records, some of which have identical values in all fields. This is 100% correct. The second query returns nothing....
7
3311
by: KoliPoki | last post by:
Hello every body. I have a small issue. Problem: I have a table with 4 descriptor columns (type). I need to formulate a query to retrieve a count for each type so I can group by...etc. The view I have works, but doesn't work when I supplement the query with some functions... they just don't like the UNION. The real problem is I can't change any of the udf's or queries, just the view. The view is inner joined back on to the primary...
1
1870
by: SAKTHIVEL | last post by:
Hi, Im developing applications using Visual Basic and MS-Access 2003. Union query solves my specific problems. But I unable to call this query from visual basic form like other queries. The query follows: select PSCLNo,Fyearid,CompId, "CLNO" as TrType from VwCLothsrNo UNION select PSCLNo,Fyearid,CompId, "PSNO" as TrType from VwPSsrNo; Visual Basic Form Statement:
1
1611
by: ebasshead | last post by:
Hi Everyone I have four queries that Ive joined in a union query and want to add a date criteria ei between and including date A and date B. Ive tried a few things but getting errors. Can someone please guide me as to where it should go and how it should be written please. My code so far is below... SELECT , , , , , , , , FROM UNION SELECT , , , , , , , , FROM UNION SELECT , , , , , , , ,
3
372
by: paulquinlan100 | last post by:
Hi I'm trying to tweak the query below so that the second SELECT only pulls out one record per "Site_Ref", i.e. the record that has the maximum "appraisal_date" out of the 4 Appraisal_types. Is this possible? SELECT lkpAppraisalDates.Site_Ref, Max(lkpAppraisalDates.AppraisalDate) AS AppraisedDate, lkpAppraisalDates.AppraisalType
0
8411
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8323
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
8513
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7351
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6176
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5638
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4329
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2740
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1969
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.