Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>DISTINCT works globally, on <em>all</em> the columns you SELECT. Here you're getting distinct <em>pairs</em> of (sp_id, company_name) values, but the individual values of each column may show duplicates.</p> <p>That being said, it's extremely deceiving that MySQL authorizes the syntax <code>SELECT DISTINCT(company_name), sp_id</code> when it really means <code>SELECT DISTINCT(company_name, sp_id)</code>. You don't need the parentheses at all, by the way.</p> <p><strong>Edit</strong></p> <p>Actually there's a reason why <code>DISTINCT(company_name), sp_id</code> is valid syntax: adding parentheses around an expression is always legal although it can be overkill: <code>company_name</code> is the same as <code>(company_name)</code> or even <code>(((company_name)))</code>. Hence what that piece of SQL means is really: “DISTINCT [company_name in parentheses], [sp_id]”. The parentheses are attached to the column name, not the DISTINCT keyword, which, unlike aggregate function names, for example, does not need parentheses (<code>AVG sp_id</code> is not legal even if unambiguous for a human reader, it's <em>always</em> <code>AVG(sp_id)</code>.)</p> <p>For that matter, you could write <code>SELECT DISTINCT company_name, (sp_id)</code> or <code>SELECT DISTINCT (company_name), (sp_id)</code>, it's exactly the same as the plain syntax without parentheses. Putting the list of columns inside parentheses – <code>(company_name, sp_id)</code> – is not legal SQL syntax, though, you can only SELECT “plain” lists of columns, unparenthesized (the form's spell-checker tells me this last expression is not an English word but I don't care. It's Friday afternoon after all).</p> <p>Therefore, any database engine should accept this confusing syntax :-(</p>
    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. 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