473,407 Members | 2,326 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,407 software developers and data experts.

query to combine two tables

here's what i want to have happen:

results_table:
id, val1, val2
1, 2, 1
2, 1, 0
3, 1, 0
4, 1, 1

the first query (make-table) generates the following ("" AS val2):

id, val1, val2
1, 2, 0
2, 1, 0
3, 1, 0

the second query (it's an append query) results in the following:

id, val1, val2
1, 2, 0
2, 1, 0
3, 1, 0
1, 0, 1
4, 0, 1

how do i achieve what i want in the results_table?
Nov 12 '05 #1
3 2028
I thought at first that Result is supposed to have a number in place of
a zero from a superposition of tables 1 and 2, sort of like an "OR"
operation for each ID. But then you have a 4,1,1 in the result. I am
lost - how do you get that? There is no 4,1,0 record anywhere.
In other words, how the Result is achieved?

Pavel

david liu wrote:

here's what i want to have happen:

results_table:
id, val1, val2
1, 2, 1
2, 1, 0
3, 1, 0
4, 1, 1

the first query (make-table) generates the following ("" AS val2):

id, val1, val2
1, 2, 0
2, 1, 0
3, 1, 0

the second query (it's an append query) results in the following:

id, val1, val2
1, 2, 0
2, 1, 0
3, 1, 0
1, 0, 1
4, 0, 1

how do i achieve what i want in the results_table?

Nov 12 '05 #2
Pavel Romashkin <pa*************@hotmail.com> wrote in message news:<40***************@hotmail.com>...
I thought at first that Result is supposed to have a number in place of
a zero from a superposition of tables 1 and 2, sort of like an "OR"
operation for each ID. But then you have a 4,1,1 in the result. I am
lost - how do you get that? There is no 4,1,0 record anywhere.
In other words, how the Result is achieved?

oops. typo on row id=4. it should be 4, 0, 1.
Pavel

david liu wrote:

here's what i want to have happen:

results_table:
id, val1, val2
1, 2, 1
2, 1, 0
3, 1, 0
4, 1, 1

the first query (make-table) generates the following ("" AS val2):

id, val1, val2
1, 2, 0
2, 1, 0
3, 1, 0

the second query (it's an append query) results in the following:

id, val1, val2
1, 2, 0
2, 1, 0
3, 1, 0
1, 0, 1
4, 0, 1

how do i achieve what i want in the results_table?

Nov 12 '05 #3
SELECT ID, max(val1), max(val2) FROM (SELECT * FROM qry1 UNION SELECT *
FROM qry2) GROUP BY ID

should produce the result you show in the example. You need to figure
out what you want to happen if you have source records like

1, 2, 1
1, 1, 3

which is not part of your example.
Pavel

david liu wrote:

Pavel Romashkin <pa*************@hotmail.com> wrote in message news:<40***************@hotmail.com>...
I thought at first that Result is supposed to have a number in place of
a zero from a superposition of tables 1 and 2, sort of like an "OR"
operation for each ID. But then you have a 4,1,1 in the result. I am
lost - how do you get that? There is no 4,1,0 record anywhere.
In other words, how the Result is achieved?


oops. typo on row id=4. it should be 4, 0, 1.
Pavel

david liu wrote:

here's what i want to have happen:

results_table:
id, val1, val2
1, 2, 1
2, 1, 0
3, 1, 0
4, 1, 1

the first query (make-table) generates the following ("" AS val2):

id, val1, val2
1, 2, 0
2, 1, 0
3, 1, 0

the second query (it's an append query) results in the following:

id, val1, val2
1, 2, 0
2, 1, 0
3, 1, 0
1, 0, 1
4, 0, 1

how do i achieve what i want in the results_table?

Nov 12 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
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 ...
6
by: Umar Farooq | last post by:
Hello all, Please bear with the long explanation of my scenario. As I'm relatively new to the query world, I like to write my queries using the visual toos such as the "View" option in SQL...
5
by: James Foreman | last post by:
I've got lots of different tables, each pertaining to a different marketing campaign. I have another table that stores the name & schema of each of these tables, together with other information...
2
by: Pete | last post by:
Before I get started with the question, does anyone have a (single) good book recommendation for database design? Not an Access-specific book, but something geared toward helping me figure out...
1
by: ravi | last post by:
I have created the following interest to calculate the interest for the following currency pairs. I have tried to combine them in macros using conditions but the next query that is run in the macro...
1
by: snOOp | last post by:
I am trying to combine the data from two similar tables into one query, but I need for all of the records from both tables to show up and I want the ones that have matching 'emplid' to be combined...
1
by: JBoeker | last post by:
Hello, I have 3 tables in my mdb file, one contains a list of definitions, one is a list physical items, and one is a list overrides. Normally my query will join the definition physical item...
3
by: comp_databases_ms-sqlserver | last post by:
This post is related to SQL server 2000 and SQL Server 2005 all editions. Many of my stored procedures create temporary tables in the code. I want to find a way to find the query plan for these...
4
by: dreaken667 | last post by:
I have a MySQL database containing 16 tables of data. Each table has a different number of columns and there are few common field names accross tables. I do have one master table with which I connect...
11
by: sillyr | last post by:
Hi - I use Access 2007. I have two tables linked by ID. I created a query to combine the two tables. My problem is that in the query my Species_Code is text, but I need it to display the number...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
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
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
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...
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.