Hi Experts,
I have two tables- contact and organization. Both tables have the mailing addresses. Some contacts in contact table don't belong to any org so I give the link to those as individual which is an entry as organization in Org.. table.
There are certain organization which don't have any contact person listed. These two tables are linked as Org..as master and contact as slave.
I want to create a mailing list.Criteria would be
To include Contact Name, Organization name, Mailing address
where
if contact is an individual, it should include only contact's name & address - should not show individual as org name
if contact belongs to an organization then org...should be there,
if no contact associated with org then org.. name & address should show,
Everything will be based on ysnMail check box option which is in both tables.
Thanks for help to figure all this out.
raz
17 1757 NeoPa 32,556
Expert Mod 16PB
This should be easy enough to sort out if you provide the information required.
Let's start with meta-data for both tables. I may also need to revisit the rather garbled explanation of what is stored where (and how) but I'll have another look through it again when I have the meta-data handy before I will know if I can make sense of it.
This will work much better if you can post the meta-data (info about the layout / structure) of the table in the same way as I use in my example. Click on the Reply button and you will have access to all the codes I've used. - Table Name=[tblStudent]
- Field; Type; IndexInfo
-
StudentID; AutoNumber; PK
-
Family; String; FK
-
Name; String
-
University; String; FK
-
Mark; Numeric
-
LastAttendance; Date/Time
Hi NeoPa,
As per your instruction I am posting MetaData of both tables. Thanks a lot for your help.
Note: tblOrg has One-To-Many relationship on tblContact
Table: [tblOrg]
"intOrgID",number,PK"
"coop_yn",ysnCheckbox
"Active/Inactive",ysnCheckbox
"strOrgName",text
"strAddr1"text
"strAddr2",text
"strCity",text
"strProv",text
"strPC",text
"strCountry",text
"ysnMailAddrSame",ysnCheckbox
"strMailAddr1",text
"strMailAddr2",text
"strMailCity",text
"strMailProv",text
"strMailPC",text
"strMailCountry",text
"strOrgPhone",text
"strOrgEMail",text
"Mail/Don't Mail",ysnCheckbox
"Email/Don't mail",ysnCheckBox
Table: [tblContact]
"LastUpdated", Date
"intOrgIDNum",number,FK
"Active/Inactive",ysncheckbox
"intContactID",number,PK
"strTitle",text
"strGender",text
"strFName",text
"strMName",text
"strLName",text
"strConPhone1",text
"strConPhone2",text
"strConFax",text
"strConEMail",text
"strWrkPhone",text
"strExt",text
"strWrkEmail",text
"strWorkFax",text
"strCurrentEmployer",text
"PreviousEmplyr",text
"HomeAdd1",text
"HomeAdd2",text
"City",text
"Prov",text
"PCode",text
"Country",text
"strRegion",text
"strGeographicArea",text
"strRiding_Name",text
"strRiding",text
"Mail_Don't Mail",ysnCheckbox
"Email_Don't Email",ysnCheckbox
Both tables are related and we need the results as contact Name:First Name & Last Name together ( If an organization without a contact name then name of the Organization would show instead of contact name), then Organization name ( if a contact person is associated as "Individual" in table organization then word " Individual" should not show for mailing list),
mailing address from table tblOrg if a contact is linked to an organization other than "Individual", otherwise mailing address from table tblContact (i.e if Org name is "Individual").
NeoPa 32,556
Expert Mod 16PB
So, in the format I requested it would be : - Table Name=[tblOrg]
- Field; Type; IndexInfo
-
intOrgID; number; PK
-
coop_yn; Boolean
-
Active/Inactive; Boolean
-
strOrgName; String
-
strAddr1; String
-
strAddr2; String
-
strCity; String
-
strProv; String
-
strPC; String
-
strCountry; String
-
ysnMailAddrSame; Boolean
-
strMailAddr1; String
-
strMailAddr2; String
-
strMailCity; String
-
strMailProv; String
-
strMailPC; String
-
strMailCountry; String
-
strOrgPhone; String
-
strOrgEMail; String
-
Mail/Don't Mail; Boolean
-
Email/Don't mail; Boolean
- Table Name=[tblContact]
- Field; Type; IndexInfo
-
LastUpdated; Date/Time
-
intOrgIDNum; Numeric; FK
-
Active/Inactive; Boolean
-
intContactID; Numeric; PK
-
strTitle; String
-
strGender; String
-
strFName; String
-
strMName; String
-
strLName; String
-
strConPhone1; String
-
strConPhone2; String
-
strConFax; String
-
strConEMail; String
-
strWrkPhone; String
-
strExt; String
-
strWrkEmail; String
-
strWorkFax; String
-
strCurrentEmployer; String
-
PreviousEmplyr; String
-
HomeAdd1; String
-
HomeAdd2; String
-
City; String
-
Prov; String
-
PCode; String
-
Country; String
-
strRegion; String
-
strGeographicArea; String
-
strRiding_Name; String
-
strRiding; String
-
Mail_Don't Mail; Boolean
-
Email_Don't Email; Boolean
NeoPa 32,556
Expert Mod 16PB
Let me see if I can clarify your requirements a little. After rereading your original post (the language makes it a little hard to understand) I'm not so sure it can be done easily after all :(
What I think you need is a list showing all records from both tables, but matching records appear only once.
To illustrate with an example : - Table1 Table2
-
A 1 A 11
-
B 2 B 12
-
C 3 D 14
-
E 5 E 15
What I think you want is : - A 1 11
-
B 2 12
-
C 3
-
D 14
-
E 5 15
Is this right?
Hi NeoPa,
sorry if I wasn't clear enough in my question.
To me looks like you are getting it right though and can be a good starting point to custamize further if it need to be.
Thanks for your help.
raz
NeoPa 32,556
Expert Mod 16PB
I'm afraid the bad news is that Access doesn't support this type of (OUTER) join.
Fully-fledged back-end systems do tend to (MS SQL for instance) but MS Access doesn't. The way I can think of doing it is quite inefficient (poor performance for large datasets) but can be done. I will look at providing a template including some of the fields you need if you're interested.
Hi NeoPa,
Thanks for your effort for looking into it.
I think it won't be that large dataset and if some kind of solution is there then it should be good enough. So would you please spare some time and give me the solution/template.
Regards,
Raz
NeoPa 32,556
Expert Mod 16PB
You're on my list Raz, but I ran out of time tonight.
I'll try to get to it tomorrow or the next day. If not - bump the thread as a reminder.
Hi NeoPa,
Thanks for having me in your list. I'll be looking forward to your help whenever you get a chance.
Thanks,
Raz
NeoPa 32,556
Expert Mod 16PB
No worries Raz.
Try the following to see if it works for you. It will need tarting up but the principles should all be there and we can finalise details when we know we're on the right lines. - SELECT [ID],
-
Max(subQ.OrgAddr1) AS OrgAddr1,
-
Max(subQ.OrgAddr2) AS OrgAddr2,
-
Max(subQ.OrgCity) AS OrgCity,
-
Max(subQ.ContAddr1) AS ContAddr1,
-
Max(subQ.ContAddr2) AS ContAddr2,
-
Max(subQ.ContCity) AS ContCity
-
FROM (SELECT intOrgID AS ID,
-
strMailAddr1 AS OrgAddr1,
-
strMailAddr2 AS OrgAddr2,
-
strMailCity AS OrgCity,
-
Null AS ContAddr1,
-
Null AS ContAddr2,
-
Null AS ContCity
-
UNION ALL SELECT
-
intOrgIDNum AS ID,
-
Null AS OrgAddr1,
-
Null AS OrgAddr2,
-
Null AS OrgCity,
-
HomeAdd1 AS ContAddr1,
-
HomeAdd2 AS ContAddr2,
-
City AS ContCity) AS subQ
-
GROUP BY [ID]
Hi NeoPa,
Thanks for the help but somehow I am unable to get anything out of this so far as it ask at least one table or query to be part of this code.
I am sorry if it sounds like some extra work for you.
Raz
NeoPa 32,556
Expert Mod 16PB
Have you tried running it as it is Raz?
Yes I tried to run it as is and it gives the error message that I need to specify at least one table or query.
NeoPa 32,556
Expert Mod 16PB
I can't see that you should be getting that from that SQL Raz.
Try seeing if the following runs at all (It's the subquery part) : - SELECT intOrgID AS ID,
-
strMailAddr1 AS OrgAddr1,
-
strMailAddr2 AS OrgAddr2,
-
strMailCity AS OrgCity,
-
NULL AS ContAddr1,
-
NULL AS ContAddr2,
-
NULL AS ContCity
-
UNION ALL SELECT
-
intOrgIDNum AS ID,
-
NULL AS OrgAddr1,
-
NULL AS OrgAddr2,
-
NULL AS OrgCity,
-
HomeAdd1 AS ContAddr1,
-
HomeAdd2 AS ContAddr2,
-
City AS ContCity
NeoPa 32,556
Expert Mod 16PB
Now I've seen that I can see the problem.
Try this instead : - SELECT [ID],
-
Max(subQ.OrgAddr1) AS OrgAddr1,
-
Max(subQ.OrgAddr2) AS OrgAddr2,
-
Max(subQ.OrgCity) AS OrgCity,
-
Max(subQ.ContAddr1) AS ContAddr1,
-
Max(subQ.ContAddr2) AS ContAddr2,
-
Max(subQ.ContCity) AS ContCity
-
FROM (SELECT intOrgID AS ID,
-
strMailAddr1 AS OrgAddr1,
-
strMailAddr2 AS OrgAddr2,
-
strMailCity AS OrgCity,
-
NULL AS ContAddr1,
-
NULL AS ContAddr2,
-
NULL AS ContCity
-
FROM [tblOrg]
-
UNION ALL SELECT
-
intOrgIDNum AS ID,
-
NULL AS OrgAddr1,
-
NULL AS OrgAddr2,
-
NULL AS OrgCity,
-
HomeAdd1 AS ContAddr1,
-
HomeAdd2 AS ContAddr2,
-
City AS ContCity
-
FROM [tblContact]) AS subQ
-
GROUP BY [ID]
This query runs but gives very few records.
I expect around 3000 record on the base the selection I am looking for but it gives only around 100 records so need to look into this query quite in detail to figure out the right combination.
Thanks for your help.
Raz
NeoPa 32,556
Expert Mod 16PB
OK Raz.
Let me know what you discover :)
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Jaime Teng |
last post by:
Hi,
I have a table:
mysql> describe archivetable;
+-----------+----------+------+-----+---------------------+-------+
| Field | Type | Null | Key | Default | Extra |...
|
by: B. Fongo |
last post by:
I learned MySQL last year without putting it into action; that is why
I face trouble in formulating my queries. Were it a test, then you
would have passed it, because your queries did help me...
|
by: Apollo |
last post by:
I have about 20K records that result from the following query. Front end for the
database is ACCESS97 and pulling up 20K records makes a huge performance hit.
For the form in question I am using...
|
by: Apollo |
last post by:
1.2Ghz Pentium, with 1/2Gig of ram, 4.0.14MySQL, RedHat9.0
I have about 20K records that result from the following query. Front end for the
database is ACCESS97 and pulling up 20K records makes a...
|
by: Andy M |
last post by:
ALERT
There is a person by the name of Mike Cox who's trying
to turn this mailing list into a Big-8 newsgroup. Many
of you know that this and most of the other postresql
mailing lists are...
|
by: tbone |
last post by:
I'd like to have a way to add bidders who have won at least $1000 in
the last auction to my mailing list. I'm having trouble with the
update step.
To find bidders who have won at least $1000 in...
|
by: razjafry |
last post by:
Hi Experts,
I have two tables - tblContact and tblOrg
Contact table has only one option of mailing address e.g address,city,postal code
whereas Org table has two options - one simple address -...
|
by: divyac |
last post by:
I have developed an address book using php and mysql.I have all the contacts list in a table with check boxes.Now that i want to create mailing labels for the checked contacts...i.e.,the arrangements...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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...
|
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
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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...
|
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: 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...
| |