Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>The query is fine. That's the textbook right way to do it.</p> <p>The primary key should be the minimum set of fields that uniquely identify a record. Is your example above your actual database or just a simplified or hypothetical example? Because it's pretty unlikely that first name plus last name can be guaranteed to be unique. Are you sure you will never have two "Jim Smith"s? I don't know how the "path" is defined. Maybe that's under your control so that you could guarantee that it's unique.</p> <p>Don't add fields to a primary key just because this is what you want to sort or select on. Use alternate indexes for that.</p> <p><strong>Update based on wild guesses about your examples</strong></p> <p>I don't know what your data means or what you're trying to do. But I'd guess that first and last name are really dependent on the path. That is, you won't have:</p> <pre><code>path vers first name last name ---- ---- ---------- --------- /foo/fredm 1 Fred Miller /foo/fredm 2 Fred Miller /foo/fredm 1 Sally Jones </code></pre> <p>If that's true, then you really should have a table with Path, First Name, Last Name, maybe other data, and key of Path. Then a separate table with Path and Version and whatever data is dependent on the version.</p> <p>Otherwise, there is the potential for your database to contain contradictory data. If a Path is supposed to map to only one name, what happens if, by some sort of coding or data entry mistake, you get one record with path "fredm" and name "Fred Miller" and another with path "fredm" and name "Frank Mendel"? Queries expecting them to always be the same could end up picking one at random and giving inconsistent results, or you could get two records where you thought you should have one, etc. One of the prime rules of good database design is: Don't store redundant data.</p>
 

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