Note that there are some explanatory texts on larger screens.

plurals
  1. POSQL - Nested select statement?
    primarykey
    data
    text
    <p>I have 2 tables, ticket and ticket_custom.<br> Here are how the tables are set up.<img src="https://lh3.ggpht.com/_BExRqkFgz70/SfIKYSErMxI/AAAAAAAAAHk/pALtXucgIS8/howTablesAreDefined.jpg" alt="alt text"></p> <p>I have a web interface where I can change the state (value in the table ticket_custom) The web interface adds a new entry instead of updating the original entry. </p> <pre><code>ticket name value 1 state Ready for Final Verification 2 state Ready for Final Verification 1 state Verified </code></pre> <p>The last row is added</p> <p>So I need to modify the queries.</p> <pre><code> SELECT p.value AS __color__, id AS ticket, summary, component, version, c.value AS state, milestone, t.type AS type, owner, status, time AS created, changetime AS _changetime, description AS _description, reporter AS _reporter FROM ticket t, ticket_custom c LEFT JOIN enum p ON p.name = t.priority AND p.type = 'priority' AND id = c.ticket WHERE status &lt;&gt; 'closed' AND id = c.ticket ORDER BY CAST(p.value AS int), milestone, t.type, time, c.ticket </code></pre> <p>The query now returns both entries. I tried to add a nested select in the where clause. </p> <pre><code>SELECT g.ticket FROM ticket_custom g WHERE g.ticket = id ORDER BY g.ticket DESC LIMIT 1 </code></pre> <p>So -</p> <pre><code>SELECT p.value AS __color__, id AS ticket, summary, component, version, c.value AS state, milestone, t.type AS type, owner, status, time AS created, changetime AS _changetime, description AS _description, reporter AS _reporter FROM ticket t, ticket_custom c LEFT JOIN enum p ON p.name = t.priority AND p.type = 'priority' AND id = c.ticket WHERE status &lt;&gt; 'closed' AND id = c.ticket and ( SELECT g.ticket FROM ticket_custom g WHERE g.ticket = id ORDER BY g.ticket DESC LIMIT 1 ) ORDER BY CAST(p.value AS int), milestone, t.type, time, c.ticket </code></pre> <p>Clearly I'm doing something wrong. </p>
    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. 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