Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <ol> <li><p>To get your user's data based on their email, you you do need a <code>JOIN</code>. You will join your tables based on AccountID (make sure it is the <code>Primary Key</code> on both tables, so it's fast) and you will test the <code>AccountEmail</code> in the <code>WHERE</code> clause. Make sure you have an index on the <code>AccountEmail</code> column, so it is quick also.</p> <p>Query:</p> <pre><code>SELECT AD.AccountID, AD.AccountPassword, AD.BandID, AU.* FROM AccountDetails AD JOIN AccountUsage AU on AU.AccountID = AD.AccountID WHERE AD.AccountEmail = ? </code></pre> <p>I have aliased AccountDetails to AD and AccountUsage to AU, this makes disambiguating the columns in the tables easier, so you don't have to type the full table name each time you need to reference it.</p></li> <li><p>To update <code>LastLogin</code> you have to run a separate <code>UPDATE</code> query</p></li> <li><p>Foreign Keys won't really help you pull the data out, here. Foregin Keys are built to maintain data integrity. Meaning you'd set a Foregin Key constraint for AccountID on <code>AccountUsage</code> which links back to <code>AccountDetails</code>, and you wouldn't be able to insert any rows into <code>AccountUsage</code> which didn't reference back to a row in <code>AccountDetails</code>. That might be a little confusing, but the takeaway is - you don't really need it here to pull data out. It's just a structural feature that helps you maintain consistency with your data.</p></li> </ol>
    singulars
    1. This table or related slice is empty.
    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.
 

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