Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Yes, well, half your problems are due to not having a resolved Data Model, and that will cause problems in SQL everywhere; if you fix that, the SQL will be much easier. The other half is not being able to use SQL effectively.</p> <ol> <li><p>You have not posted info re the other tables, so I can't give you a reasonably accurate DM, I am going just from what you have provided, and of course made huge assumptions about the other related tables, which are most probably incorrect. If you provide the info, I can provide an accurate DM.</p> <ul> <li>Is a Category Independent or "owned" by only one Member ? <ul> <li>Modelled: "No."</li> </ul></li> <li>On what basis is a Category "shared" ? <ul> <li>Modelled: sharing is the same as ownership; a shared Category is simply one that is owned by more than one Member</li> </ul></li> <li>Then, what is the difference between an "owned" Category and a "shared" Category ?</li> <li>We do not know what the Categories are for (Subjects ?). In which case why are Categories, not Subjects, owned/shared by Members ?</li> <li>Your Category, if it is owned, really should not be called Category, rather something like CategoryOwned.</li> <li>I cannot see how CategoryViewed shows all the Views; it allows only one (the last ?) view per Member. Where is the ViewDate ? <ul> <li>Modelled: As a log of Views. If you want only one (the last) view per Member, remove ViewDate from the PK. </li> </ul></li> </ul> <p><a href="http://www.softwaregems.com.au/Documents/Student%20Resolutions/DavidRyder%20DM.pdf" rel="nofollow"><strong>Interim Data Model</strong></a></p></li> <li><p>It is not a good idea to perform Unions, etc, unless you absolutely have to. Right now the data is small; when the database is large, you will certainly feel the effects of the work tables being created; filled; destroyed. So far from your requirement, there is no need for Unions, Distincts, worktables, etc. But the DM does present problems.</p></li> <li><p>SQL. I cannot see how your SQL (or any of the other answers) retrieves your requirement of "the last time that category was viewed [by any Member]". Additionally, you should always try to get your SQL correct (returning the correct set of data) for each set, before Unioning, etc: you have not done that; that is why you have duplicate rows. Using DISTINCT is a stupid way to fix the problem; you are correct in seeking understanding instead.</p></li> <li><p>I won't attempt to provide the SQL for your model. Here is the SQL for the Interim Data Model provided. Obviously, this is much, much cheaper than Unions: <pre><code>SELECT [Member] = Member.Name, [Category = Category.Name, [LastView] = ( SELECT MAX(ViewDate) FROM CategoryView WHERE CategoryId = cm.CategoryId ) FROM CategoryMember cm, Member m, Category c WHERE cm.MemberId = '$MemberId' AND m.MemberId = cm.MemberId AND c.CategoryId = cm.CategoryId</pre></code></p></li> </ol>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload