Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Instead of using an inner query, use joins.</p> <p>Based on your hard coded query, the answer seems to be</p> <pre><code>SELECT request.SPOC_id, request.order_created, request.order_updated FROM request inner join agents ON agents.idAgent = request.FK_agentid WHERE Agent_idAgent = 1 LIMIT 0 , 30 </code></pre> <p>In order to make this query more general, you need to replace the hard coded '1' with a parameter (your syntax may vary)</p> <pre><code>SELECT request.SPOC_id, request.order_created, request.order_updated FROM request inner join agents ON agents.idAgent = request.FK_agentid WHERE Agent_idAgent = :p1 LIMIT 0 , 30 </code></pre> <p>How do you use the parameter? The query presumably is being called from some programming language. In Delphi, I would write the following</p> <pre><code>with MyQuery do begin parambyname ('p1').asinteger:= 7; open; ... close end; </code></pre> <p>This would retrieve all the requests for agent 7. As your table design does not allow an agent to have a name (the name is to be found in the Person table), it's more difficult to show how to retrieve all the requests for the agent whose name is kwk.stack.</p> <pre><code>SELECT request.SPOC_id, request.order_created, request.order_updated FROM request inner join agents ON agents.idAgent = request.agent_agentid inner join person on person.idperson = agents.person_idperson WHERE person.name = 'kwk.stack' </code></pre> <p>The above is based on the question as it was first asked. Edits to the question may mean that the above no longer answers the question being asked.</p> <p>I strongly suggest that you change the names of your tables - these are normally plural, eg People, Agents, Requests, etc - and the field names within the tables - replace 'agent_agentid' with 'agent'; 'person_idperson' with 'person', etc. </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.
 

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