Note that there are some explanatory texts on larger screens.

plurals
  1. POmysql query grouping logic
    text
    copied!<p>My this query getting 6 records from resale table for shipwynum 151513 : -</p> <pre><code> select re.recdat, re.resaleid, IF (re.benownsal != '', owsal.ownshortnam, if ((re.grptypsal != '' &amp;&amp; re.bogrpidsal != ''), if (bosal.bogrpshort != '', bosal.bogrpshort, bosal.bogrpnam), cou1.nation)) as seller, IF (re.benownpur != '', owpur.ownshortnam, if ((re.grptyppur != '' &amp;&amp; re.bogrpidpur != ''), if (bopur.bogrpshort != '', bopur.bogrpshort, bopur.bogrpnam), cou.nation)) as buyer, re.benownpur, re.grptyppur, re.bogrpidpur, re.statuscod, re.showinob, re.benownsal, re.grptypsal, re.bogrpidsal from resale as re left join owner as owpur on owpur.ownwynum = re.benownpur left join owner as owsal on owsal.ownwynum = re.benownsal left join bogroup as bopur on bopur.bogrpid = re.bogrpidpur left join bogroup as bosal on bosal.bogrpid = re.bogrpidsal left join country as cou on cou.coucod = re.buynation left join country as cou1 on cou1.coucod = re.selnation where re.shipwynum = '151513' and re.deleted = 'N' order by re.saltyp desc, re.recdat </code></pre> <p>Here i have added sample data screen shot got from above query for shipwynum 15153:-</p> <p><img src="https://i.stack.imgur.com/kr5Ok.png" alt="enter image description here"> When i add limit clause <code>LIMIT 1</code> then its getting the first one record which i expected. But its only for one ship that have shipwynum = 151513. I want to get first one record for every ship. </p> <p>What changes i do for get such a records for every ship.</p> <p>Any help would be greatly appreciated. </p> <p>Thanks. </p>
 

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