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

Need help for mailing list query

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
Apr 23 '08 #1
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.
Expand|Select|Wrap|Line Numbers
  1. Table Name=[tblStudent]
  2. Field; Type; IndexInfo
  3. StudentID; AutoNumber; PK
  4. Family; String; FK
  5. Name; String
  6. University; String; FK
  7. Mark; Numeric
  8. LastAttendance; Date/Time
Apr 24 '08 #2
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").
Apr 25 '08 #3
NeoPa
32,556 Expert Mod 16PB
So, in the format I requested it would be :
Expand|Select|Wrap|Line Numbers
  1. Table Name=[tblOrg]
  2. Field; Type; IndexInfo
  3. intOrgID; number; PK
  4. coop_yn; Boolean
  5. Active/Inactive; Boolean
  6. strOrgName; String
  7. strAddr1; String
  8. strAddr2; String
  9. strCity; String
  10. strProv; String
  11. strPC; String
  12. strCountry; String
  13. ysnMailAddrSame; Boolean
  14. strMailAddr1; String
  15. strMailAddr2; String
  16. strMailCity; String
  17. strMailProv; String
  18. strMailPC; String
  19. strMailCountry; String
  20. strOrgPhone; String
  21. strOrgEMail; String
  22. Mail/Don't Mail; Boolean
  23. Email/Don't mail; Boolean
Expand|Select|Wrap|Line Numbers
  1. Table Name=[tblContact]
  2. Field; Type; IndexInfo
  3. LastUpdated;  Date/Time
  4. intOrgIDNum; Numeric; FK
  5. Active/Inactive; Boolean
  6. intContactID; Numeric; PK
  7. strTitle; String
  8. strGender; String
  9. strFName; String
  10. strMName; String
  11. strLName; String
  12. strConPhone1; String
  13. strConPhone2; String
  14. strConFax; String
  15. strConEMail; String
  16. strWrkPhone; String
  17. strExt; String
  18. strWrkEmail; String
  19. strWorkFax; String
  20. strCurrentEmployer; String
  21. PreviousEmplyr; String
  22. HomeAdd1; String
  23. HomeAdd2; String
  24. City; String
  25. Prov; String
  26. PCode; String
  27. Country; String
  28. strRegion; String
  29. strGeographicArea; String
  30. strRiding_Name; String
  31. strRiding; String
  32. Mail_Don't Mail; Boolean
  33. Email_Don't Email; Boolean
Apr 25 '08 #4
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 :
Expand|Select|Wrap|Line Numbers
  1. Table1       Table2
  2.  A  1         A  11
  3.  B  2         B  12
  4.  C  3         D  14
  5.  E  5         E  15
What I think you want is :
Expand|Select|Wrap|Line Numbers
  1. A 1 11
  2. B 2 12
  3. C 3
  4. D   14
  5. E 5 15
Is this right?
Apr 25 '08 #5
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
Apr 25 '08 #6
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.
Apr 28 '08 #7
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
Apr 29 '08 #8
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.
Apr 30 '08 #9
Hi NeoPa,
Thanks for having me in your list. I'll be looking forward to your help whenever you get a chance.
Thanks,
Raz
Apr 30 '08 #10
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.
Expand|Select|Wrap|Line Numbers
  1. SELECT [ID],
  2.        Max(subQ.OrgAddr1) AS OrgAddr1,
  3.        Max(subQ.OrgAddr2) AS OrgAddr2,
  4.        Max(subQ.OrgCity) AS OrgCity,
  5.        Max(subQ.ContAddr1) AS ContAddr1,
  6.        Max(subQ.ContAddr2) AS ContAddr2,
  7.        Max(subQ.ContCity) AS ContCity
  8. FROM (SELECT intOrgID AS ID,
  9.              strMailAddr1 AS OrgAddr1,
  10.              strMailAddr2 AS OrgAddr2,
  11.              strMailCity AS OrgCity,
  12.              Null AS ContAddr1,
  13.              Null AS ContAddr2,
  14.              Null AS ContCity
  15.       UNION ALL SELECT
  16.              intOrgIDNum AS ID,
  17.              Null AS OrgAddr1,
  18.              Null AS OrgAddr2,
  19.              Null AS OrgCity,
  20.              HomeAdd1 AS ContAddr1,
  21.              HomeAdd2 AS ContAddr2,
  22.              City AS ContCity) AS subQ
  23. GROUP BY [ID]
May 1 '08 #11
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
May 2 '08 #12
NeoPa
32,556 Expert Mod 16PB
Have you tried running it as it is Raz?
May 2 '08 #13
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.
May 2 '08 #14
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) :
Expand|Select|Wrap|Line Numbers
  1. SELECT intOrgID AS ID,
  2.        strMailAddr1 AS OrgAddr1,
  3.        strMailAddr2 AS OrgAddr2,
  4.        strMailCity AS OrgCity,
  5.        NULL AS ContAddr1,
  6.        NULL AS ContAddr2,
  7.        NULL AS ContCity
  8. UNION ALL SELECT
  9.        intOrgIDNum AS ID,
  10.        NULL AS OrgAddr1,
  11.        NULL AS OrgAddr2,
  12.        NULL AS OrgCity,
  13.        HomeAdd1 AS ContAddr1,
  14.        HomeAdd2 AS ContAddr2,
  15.        City AS ContCity
May 2 '08 #15
NeoPa
32,556 Expert Mod 16PB
Now I've seen that I can see the problem.

Try this instead :
Expand|Select|Wrap|Line Numbers
  1. SELECT [ID],
  2.        Max(subQ.OrgAddr1) AS OrgAddr1,
  3.        Max(subQ.OrgAddr2) AS OrgAddr2,
  4.        Max(subQ.OrgCity) AS OrgCity,
  5.        Max(subQ.ContAddr1) AS ContAddr1,
  6.        Max(subQ.ContAddr2) AS ContAddr2,
  7.        Max(subQ.ContCity) AS ContCity
  8. FROM (SELECT intOrgID AS ID,
  9.              strMailAddr1 AS OrgAddr1,
  10.              strMailAddr2 AS OrgAddr2,
  11.              strMailCity AS OrgCity,
  12.              NULL AS ContAddr1,
  13.              NULL AS ContAddr2,
  14.              NULL AS ContCity
  15.       FROM [tblOrg]
  16.       UNION ALL SELECT
  17.              intOrgIDNum AS ID,
  18.              NULL AS OrgAddr1,
  19.              NULL AS OrgAddr2,
  20.              NULL AS OrgCity,
  21.              HomeAdd1 AS ContAddr1,
  22.              HomeAdd2 AS ContAddr2,
  23.              City AS ContCity
  24.       FROM [tblContact]) AS subQ
  25. GROUP BY [ID]
May 2 '08 #16
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
May 8 '08 #17
NeoPa
32,556 Expert Mod 16PB
OK Raz.

Let me know what you discover :)
May 8 '08 #18

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

Similar topics

0
by: Jaime Teng | last post by:
Hi, I have a table: mysql> describe archivetable; +-----------+----------+------+-----+---------------------+-------+ | Field | Type | Null | Key | Default | Extra |...
0
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...
0
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...
0
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...
4
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...
3
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...
3
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 -...
2
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: 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
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...
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...

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.