title: Using a SELECT inside of another SELECT statement where the nested SELECT takes as input a value from the first SELECT
body: <p>First I apologize for the title but I just don't know how to put it in one row.</p>
  
  <p>All master accounts has 1 or more subaccounts. The way is setup is that every account has unique lskinid. If the account is a master-Account lskinid and masterlskin are the same because it hold it's own lskinid. 
  If the account is a sub-account then under the column masterlskin it will hold the lskinid of it's master account. With this said, all the accounts, including sub-accounts, has their own account name (refname).
  Now here is where the problem starts. I want to select the MASTER ACCOUNT NAME (refname of the master account) and the second column to be the total number of sub-accounts for that master account. Since I am grouping by master-account (masterlskin)
  there will be multiple records for account name (refname) but I want to show the refname for the master account.</p>
  
  <p>What I did so far is:</p>
  
  <pre><code>SELECT count(lskinid) AS "Total Subaccounts", 
  (SELECT refname FROM lskin WHERE lskinid = masterlskin) AS "Account Name"
  FROM lskin
  WHERE isactive = 1
  Group by masterlskin
  order by count(lskinid) DESC
  </code></pre>
  
  <p>Table lskin has:
  -refname (account name)
  -lskinid (accouont id)
  -masterlskin (master account id)
  -isactive (if is active account)
  .
  .
  .</p>
  
  <p>This doesn't work because the sub-query is returning multiple records, which make sense because it is looking through all the records on that table. Is there any way to tell that sub-query to take the values only on the current row. More precisely, the variable MASTERLSKIN (the one I wrote all capitals on the sub-query) to get the value of the masterlskin on the current row?</p>
  
  <p>Thank you in advance   </p>
  
  <p>I am getting this error message:
  <a href="https://i.stack.imgur.com/khO3c.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/khO3c.png" alt="enter image description here"></a></p>
  
  <p>Update:
  I fixed it. One of the "in" parts was not on square brackets. Added that and now is working perfect.</p>