473,387 Members | 1,742 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,387 software developers and data experts.

Merge 2 tables with conditions

Hi!

I have 2 tables:

Table Users:
ID
Name
Password
Birth

Table Status:
ID
Status

Both tables are related by "ID" field, but both tables have not the
same number of elements

I want to obtain a new table with this structure:

Table Result:
ID
Name
Password
Birth
Status

As I said before both tables have not the same number of elements
(rows) so in my result table, "Status" field should be empty for those
"ID"'s not found in "Status" table.

Example:

Users: 1 2 3
John Mary Peter
1234 3333 3456
5/11/81 9/3/80 7/7/69

Staus: 1 3
CODE1 CODE5

Result: 1 2 3
John Mary Peter
1234 3333 3456
5/11/81 9/3/80 7/7/69
CODE1 (EMPTY) CODE5

I am working with access, but I have knwoledge of SQL.

Thanks in advance.

Nov 6 '07 #1
2 1467
On Tue, 06 Nov 2007 00:26:48 -0800, Vicente <uc***@ono.comwrote:

You need an outer join.
Create new query select both tables draw a line between the two ID
fields if it's not created automatically right-click the line >
Choose 'Include all from Users and only ...'

-Tom.

>Hi!

I have 2 tables:

Table Users:
ID
Name
Password
Birth

Table Status:
ID
Status

Both tables are related by "ID" field, but both tables have not the
same number of elements

I want to obtain a new table with this structure:

Table Result:
ID
Name
Password
Birth
Status

As I said before both tables have not the same number of elements
(rows) so in my result table, "Status" field should be empty for those
"ID"'s not found in "Status" table.

Example:

Users: 1 2 3
John Mary Peter
1234 3333 3456
5/11/81 9/3/80 7/7/69

Staus: 1 3
CODE1 CODE5

Result: 1 2 3
John Mary Peter
1234 3333 3456
5/11/81 9/3/80 7/7/69
CODE1 (EMPTY) CODE5

I am working with access, but I have knwoledge of SQL.

Thanks in advance.
Nov 6 '07 #2
SELECT users.id, users.name, users.password, status.status, users.birth
FROM users LEFT JOIN status
ON users.id = status.id

In the query designer, you can switch from the SQL view to the graphical
view to see how your could have done it, graphically.
Hoping it may help,
Vanderghast, Access MVP
"Vicente" <uc***@ono.comwrote in message
news:11**********************@d55g2000hsg.googlegr oups.com...
Hi!

I have 2 tables:

Table Users:
ID
Name
Password
Birth

Table Status:
ID
Status

Both tables are related by "ID" field, but both tables have not the
same number of elements

I want to obtain a new table with this structure:

Table Result:
ID
Name
Password
Birth
Status

As I said before both tables have not the same number of elements
(rows) so in my result table, "Status" field should be empty for those
"ID"'s not found in "Status" table.

Example:

Users: 1 2 3
John Mary Peter
1234 3333 3456
5/11/81 9/3/80 7/7/69

Staus: 1 3
CODE1 CODE5

Result: 1 2 3
John Mary Peter
1234 3333 3456
5/11/81 9/3/80 7/7/69
CODE1 (EMPTY) CODE5

I am working with access, but I have knwoledge of SQL.

Thanks in advance.

Nov 6 '07 #3

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

Similar topics

8
by: Nils | last post by:
Hello, my problem: I merged about 1.000 Tables with Create table name (variables) type=merge union=(table1,table2,...,table1000); MySQL now creates a tables, but I can't open it....
1
by: Bob Stearns | last post by:
Does the following message get generated before or after the additional conditions given in the merge are evaluated? Error: The same row of target table "NULLID.AICA" was identified more than...
11
by: UDBDBA | last post by:
Hi: This is a merge questions which has been posted and answered... in my case need more clairification when target table (tableB) matched multiple rows to be updated based on the ON condition...
3
by: cdelarte | last post by:
I would like to be able to mail merge records from multiple mysql tables using a simple template, preferably via a command line script. MSWord mail merge via ODBC will not work for me as it only...
16
by: UDBDBA | last post by:
Hi All: I need some clarification on a MERGE statement. The database is on V8 FP12 (AIX) 64bit. The source table is tableA. The target is a View "FACT" with UNION ALL because of the 512 Gig...
3
by: opeca | last post by:
Hi all, I have two tables(A, B), and I would like to attach records from these ones. Only I have two conditions, else i can use UNION. 1. Condition: If the value in col2 in A table is in...
7
by: giladp1 | last post by:
I found Albert Kallal's great "Super easy Word Merge" code in his site at: http://www.members.shaw.ca/AlbertKallal/msaccess/msaccess.html Thanks Albert so much for sharing this. I am looking...
3
peeaurjee
by: peeaurjee | last post by:
Hi! I have 2 tables: Table Users: ID Name Password Birth
1
by: joproulx | last post by:
Hello all, Here is my problem: I am trying to merge 2 datasets but I don't want to overwrite rows that are already modified in my working dataset. Example: I have one Dataset with only one...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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...

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.