{"id":725,"date":"2013-07-31T03:14:00","date_gmt":"2013-07-31T07:14:00","guid":{"rendered":"http:\/\/regina-whipp.com\/blog\/?p=725"},"modified":"2016-07-08T22:48:58","modified_gmt":"2016-07-09T02:48:58","slug":"circular-reference-well-kind-of","status":"publish","type":"post","link":"https:\/\/regina-whipp.com\/blog\/?p=725","title":{"rendered":"Circular Reference (well, kind of)&#8230;"},"content":{"rendered":"<p>You sat down to build your database and things were going great.\u00a0 You made a table for Members and one for Members Contacts.\u00a0 Only you now realize that the Members Contacts can also be Members.\u00a0 At first you think&#8230; that will be okay.\u00a0 But then you go to build your forms and realize this is a problem.\u00a0 If you create a UNION query to show all the Members, you can\u2019t edit the information AND you notice that some Member\u2019s <b>ID <\/b>is the same as some Member Contacts <b>ID<\/b>.<\/p>\n<p>This is when you need to think outside the box.\u00a0 You can store all your Members, Company\u2019s, Contacts and Individuals, in the same table and still keep track of Member\u2019s Contacts which will make querying much easier.\u00a0 But let\u2019s be clear, this is the exception to the rule, not the rule.\u00a0 Normally, I would recommend a table for Company&#8217;s and a seperate table for Contacts.\u00a0 However, we all know in the real world the *<strong>standard<\/strong>* does not always apply!<\/p>\n<p>For this example we\u2019ll use the table as outlined below (To see the complete Data Model and download the Sample Database, <a href=\"http:\/\/www.access-diva.com\/dm6.html\" target=\"_blank\">click here<\/a>)&#8230;<\/p>\n<p><b>tblMembers<br \/>\n<\/b>mActive<br \/>\nmMemberID (PK)<br \/>\nmRegistrationID<br \/>\nmAttachedTo (circular reference to Member ID in <b>this<\/b> table)<br \/>\nmCompanyName<br \/>\nmRegistrationID<br \/>\nmTitle<br \/>\nmFirstName<br \/>\nmLastName<br \/>\netc&#8230;<\/p>\n<p>In the table we\u2019ll enter&#8230;<\/p>\n<div id=\"attachment_727\" style=\"width: 861px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-727\" class=\"wp-image-727 size-full\" src=\"http:\/\/regina-whipp.com\/blog\/wp-content\/uploads\/2013\/08\/tblComplaints.png\" alt=\"tblComplaints\" width=\"851\" height=\"133\" srcset=\"https:\/\/regina-whipp.com\/blog\/wp-content\/uploads\/2013\/08\/tblComplaints.png 851w, https:\/\/regina-whipp.com\/blog\/wp-content\/uploads\/2013\/08\/tblComplaints-300x46.png 300w, https:\/\/regina-whipp.com\/blog\/wp-content\/uploads\/2013\/08\/tblComplaints-150x23.png 150w, https:\/\/regina-whipp.com\/blog\/wp-content\/uploads\/2013\/08\/tblComplaints-400x62.png 400w\" sizes=\"auto, (max-width: 851px) 100vw, 851px\" \/><p id=\"caption-attachment-727\" class=\"wp-caption-text\">Figure 1<\/p><\/div>\n<p>As you can see Access Diva (Company) has a <strong>MemberID<\/strong> of 1.\u00a0 Gina Whipp, who works for Access Diva but is also a Member has a <strong>MemberID <\/strong><strong>of<\/strong> 2.\u00a0 In order to *relate* Gina to the Company in the <strong>mAttachedTo <\/strong>field you would enter a 1 or, since this would be on a Form with a Combo Box to select from, you would select Access Diva (Figure 2).<\/p>\n<div id=\"attachment_728\" style=\"width: 251px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-728\" class=\"wp-image-728 size-full\" src=\"http:\/\/regina-whipp.com\/blog\/wp-content\/uploads\/2013\/08\/MemberContacts.png\" alt=\"MemberContacts\" width=\"241\" height=\"148\" srcset=\"https:\/\/regina-whipp.com\/blog\/wp-content\/uploads\/2013\/08\/MemberContacts.png 241w, https:\/\/regina-whipp.com\/blog\/wp-content\/uploads\/2013\/08\/MemberContacts-150x92.png 150w\" sizes=\"auto, (max-width: 241px) 100vw, 241px\" \/><p id=\"caption-attachment-728\" class=\"wp-caption-text\">Figure 2<\/p><\/div>\n<p>The RowSource for the Combo Box in Figure 2\u00a0is&#8230;<\/p>\n<p>SELECT tblMembers.mMemberID, tblMembers.mCompanyName FROM tblMembers WHERE (((tblMembers.mAttachedTo) Is Null));<\/p>\n<p>You can either build one Form to enter Members OR you could build a form that has a Main Form for Company&#8217;s and Subform for Company Contacts.\u00a0 Using the Main Form\/Subform scenario you could use the <strong>mMemberTypeID<\/strong> or the <strong>mRegistrationID<\/strong> to identify which <strong>Contacts <\/strong>are also Members.\u00a0 To seperate the two is easy&#8230; Take a look at the following two queries&#8230;<\/p>\n<p><strong>Companies&#8230;<\/strong><\/p>\n<p>SELECT tblMembers.mMemberID, tblMembers.mCompanyName, tblMembers.mFirstName, tblMembers.mLastName<br \/>\nFROM tblMembers<br \/>\n<b>WHERE (((tblMembers.mAttachedTo) Is Null))<\/b>;<\/p>\n<p><strong>Contacts\/Individuals&#8230;<\/strong><\/p>\n<p>SELECT tblMembers.mMemberID, tblMembers.mCompanyName, tblMembers.mFirstName, tblMembers.mLastName<br \/>\nFROM tblMembers<br \/>\n<b>WHERE (((tblMembers.mAttachedTo) Is Not Null))<\/b>;<\/p>\n<p>Download the Sample Database here&#8230;\u00a0 <a href=\"http:\/\/www.access-diva.com\/myzipfiles\/Complaints.zip\" target=\"_blank\">Complaints.zip<\/a><\/p>\n<div class=\"pvc_clear\"><\/div>\n<p id=\"pvc_stats_725\" class=\"pvc_stats all  \" data-element-id=\"725\" style=\"\"><i class=\"pvc-stats-icon medium\" aria-hidden=\"true\"><svg aria-hidden=\"true\" focusable=\"false\" data-prefix=\"far\" data-icon=\"chart-bar\" role=\"img\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" viewBox=\"0 0 512 512\" class=\"svg-inline--fa fa-chart-bar fa-w-16 fa-2x\"><path fill=\"currentColor\" d=\"M396.8 352h22.4c6.4 0 12.8-6.4 12.8-12.8V108.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v230.4c0 6.4 6.4 12.8 12.8 12.8zm-192 0h22.4c6.4 0 12.8-6.4 12.8-12.8V140.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v198.4c0 6.4 6.4 12.8 12.8 12.8zm96 0h22.4c6.4 0 12.8-6.4 12.8-12.8V204.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v134.4c0 6.4 6.4 12.8 12.8 12.8zM496 400H48V80c0-8.84-7.16-16-16-16H16C7.16 64 0 71.16 0 80v336c0 17.67 14.33 32 32 32h464c8.84 0 16-7.16 16-16v-16c0-8.84-7.16-16-16-16zm-387.2-48h22.4c6.4 0 12.8-6.4 12.8-12.8v-70.4c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v70.4c0 6.4 6.4 12.8 12.8 12.8z\" class=\"\"><\/path><\/svg><\/i> <img loading=\"lazy\" decoding=\"async\" width=\"16\" height=\"16\" alt=\"Loading\" src=\"https:\/\/regina-whipp.com\/blog\/wp-content\/plugins\/page-views-count\/ajax-loader-2x.gif\" border=0 \/><\/p>\n<div class=\"pvc_clear\"><\/div>\n","protected":false},"excerpt":{"rendered":"<p>You sat down to build your database and things were going great. You made a table for Members and one for Members Contacts. Only you now realize that the Members Contacts can also be Members. At first you think&#8230; that will be okay. But then you go to build your forms and realize this is [&#8230;]<\/p>\n<div class=\"pvc_clear\"><\/div>\n<p id=\"pvc_stats_725\" class=\"pvc_stats all  \" data-element-id=\"725\" style=\"\"><i class=\"pvc-stats-icon medium\" aria-hidden=\"true\"><svg aria-hidden=\"true\" focusable=\"false\" data-prefix=\"far\" data-icon=\"chart-bar\" role=\"img\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" viewBox=\"0 0 512 512\" class=\"svg-inline--fa fa-chart-bar fa-w-16 fa-2x\"><path fill=\"currentColor\" d=\"M396.8 352h22.4c6.4 0 12.8-6.4 12.8-12.8V108.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v230.4c0 6.4 6.4 12.8 12.8 12.8zm-192 0h22.4c6.4 0 12.8-6.4 12.8-12.8V140.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v198.4c0 6.4 6.4 12.8 12.8 12.8zm96 0h22.4c6.4 0 12.8-6.4 12.8-12.8V204.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v134.4c0 6.4 6.4 12.8 12.8 12.8zM496 400H48V80c0-8.84-7.16-16-16-16H16C7.16 64 0 71.16 0 80v336c0 17.67 14.33 32 32 32h464c8.84 0 16-7.16 16-16v-16c0-8.84-7.16-16-16-16zm-387.2-48h22.4c6.4 0 12.8-6.4 12.8-12.8v-70.4c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v70.4c0 6.4 6.4 12.8 12.8 12.8z\" class=\"\"><\/path><\/svg><\/i> <img loading=\"lazy\" decoding=\"async\" width=\"16\" height=\"16\" alt=\"Loading\" src=\"https:\/\/regina-whipp.com\/blog\/wp-content\/plugins\/page-views-count\/ajax-loader-2x.gif\" border=0 \/><\/p>\n<div class=\"pvc_clear\"><\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[63],"tags":[35,18,40],"class_list":["post-725","post","type-post","status-publish","format-standard","hentry","category-database-design","tag-data-model","tag-database-design","tag-table-design","odd"],"_links":{"self":[{"href":"https:\/\/regina-whipp.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/725","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/regina-whipp.com\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/regina-whipp.com\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/regina-whipp.com\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/regina-whipp.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=725"}],"version-history":[{"count":9,"href":"https:\/\/regina-whipp.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/725\/revisions"}],"predecessor-version":[{"id":1278,"href":"https:\/\/regina-whipp.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/725\/revisions\/1278"}],"wp:attachment":[{"href":"https:\/\/regina-whipp.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=725"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/regina-whipp.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=725"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/regina-whipp.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=725"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}