Note that there are some explanatory texts on larger screens.

plurals
  1. POsql query get multiple values from same column for one row
    primarykey
    data
    text
    <p>I'm getting multiple rows per staff if they have multiple contact values, but I just want one row per staff listing their Last Name, First Name, Division Name, Email and Phone.</p> <p>So it should like like this</p> <pre><code> First Name Last Name Division Email Phone Test Guy Exec test@gmail.com 555-5555 </code></pre> <p>Here is what I have, but it's not working:</p> <pre><code> SELECT sr.LastName, sr.FirstName, dd.Name, Email = (select sc.ContactValue FROM StaffContactInformation as sc INNER JOIN StaffRoster as roster on sc.StaffID = roster.ID where sc.ContactTypeID = 3 and roster.ID = sr.ID), Phone = (SELECT sc1.ContactValue FROM StaffContactInformation as sc1 INNER JOIN StaffRoster as roster on sc1.StaffID = roster.ID where sc1.ContactTypeID = 1) FROM StaffRoster as sr left join dictDivisions as dd on sr.DivisionID = dd.Id left join StaffContactInformation as sci on sr.ID = sci.StaffID inner join dictStaffContactTypes as dsct on sci.ContactTypeID = dsct.ID where (sr.Active = 1 and sr.isContractor = 0 ) ORDER BY sr.LastName, sr.FirstName </code></pre> <p>I solved it with the following query:</p> <pre><code> SELECT sr.LastName, sr.FirstName, dd.Name, Email = (select sc.ContactValue FROM StaffContactInformation as sc INNER JOIN StaffRoster as roster on sc.StaffID = roster.ID where sc.ContactTypeID = 3 and roster.ID = sr.ID), Phone = (SELECT sc.ContactValue FROM StaffContactInformation as sc INNER JOIN StaffRoster as roster on sc.StaffID = roster.ID where sc.ContactTypeID = 1 and roster.ID = sr.ID) FROM StaffRoster as sr left join dictDivisions as dd on sr.DivisionID = dd.Id where (sr.Active = 1 and sr.isContractor = 0 ) ORDER BY sr.LastName, sr.FirstName </code></pre>
    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.
 

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