473,503 Members | 1,638 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 1164
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,557 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
3541
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 ...
0
3937
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,...
4
1919
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...
0
1582
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...
2
4007
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...
5
2264
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...
7
3298
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...
1
1858
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...
1
1602
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...
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...
0
7202
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,...
0
7280
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
7332
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7462
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...
1
5014
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...
0
4673
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...
0
3167
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
1
736
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
382
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.