Note that there are some explanatory texts on larger screens.

plurals
  1. POT-SQL SELECT with GROUP BY id
    primarykey
    data
    text
    <p>I have table with '<strong>People</strong>'</p> <p>Columns</p> <ul> <li>ID</li> <li>Name</li> <li>Age</li> </ul> <p>And table with '<strong>Notes</strong>':</p> <p>Columns</p> <ul> <li>ID</li> <li>Text</li> <li>FK_Author</li> </ul> <p>I want to select count of notes for all authors from people table and their name and age, but I want to group it by PERSON ID, not name. There are many situations when people have same name, but ID is obviously always different.</p> <p>EXAMPLE (input)</p> <p><strong>PEOPLE:</strong></p> <pre><code>╔════╦═══════╦═════╗ ║ ID ║ NAME ║ AGE ║ ╠════╬═══════╬═════╣ ║ 1 ║ John ║ 12 ║ ║ 2 ║ Annie ║ 29 ║ ║ 3 ║ John ║ 44 ║ ╚════╩═══════╩═════╝ </code></pre> <p><strong>NOTES:</strong></p> <pre><code>╔════╦═══════╦═══════════╗ ║ ID ║ TEXT ║ FK_AUTHOR ║ ╠════╬═══════╬═══════════╣ ║ 1 ║ 'aaa' ║ 1 ║ ║ 2 ║ 'aaa' ║ 1 ║ ║ 3 ║ 'aaa' ║ 2 ║ ║ 4 ║ 'aaa' ║ 2 ║ ║ 5 ║ 'aaa' ║ 3 ║ ╚════╩═══════╩═══════════╝ </code></pre> <p><strong>Expected result:</strong></p> <pre><code>╔═══════╦═════╦════════════╗ ║ NAME ║ AGE ║ TOTALCOUNT ║ ╠═══════╬═════╬════════════╣ ║ John ║ 12 ║ 2 ║ ║ Annie ║ 29 ║ 2 ║ ║ John ║ 44 ║ 1 ║ ╚═══════╩═════╩════════════╝ </code></pre> <p>When I select data I have to group by Name too if I want to select this column because if I dont, I get error.</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.
 

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