Note that there are some explanatory texts on larger screens.

plurals
  1. POPHP mySQL - select unique value that not being used from dirrefent table
    primarykey
    data
    text
    <p><strong>Updates : Please see below</strong></p> <p>i have table: data</p> <pre><code>+-----------------------+--------------+-----------+ | State | d_country | d_postcode| +-----------------------+--------------+-----------+ | State1 | Country1 | 1111 | | State2 | Country2 | 2222 | | State3 | Country3 | 3333 | | State4 | Country4 | 4444 | +-----------------------+--------------+-----------+ </code></pre> <p>And another table: user</p> <pre><code>+-----------------------+--------------+-----------+ | Name | u_country | u_postcode| +-----------------------+--------------+-----------+ | Name1 | Country3 | 3333 | | Name2 | Country5 | 5555 | | Name3 | | 6666 | | Name4 | Country6 | 6666 | | Name5 | Country6 | 6666 | +-----------------------+--------------+-----------+ </code></pre> <p>What SQL should i use to:</p> <p><strike> Determine the number (count) of country that are not listed on table data. For example <code>u_postcode</code> is not listed in <code>d_postcode</code> is 5555 and 6666. It will return 2.</p> <p>List down name and what country not available in table data yet.</strike> </p> <p><strong>Updates</strong></p> <ol start="3"> <li>I want to use grouping to filter postcode and make Name3 and Name4 as different rows.</li> </ol> <p>For example:</p> <pre><code> +-----------------------+--------------+-----------+ | Name | u_country | u_postcode| +-----------------------+--------------+-----------+ | Name2 | Country5 | 5555 | | Name3 | | 6666 | | Name4 | Country6 | 6666 | +-----------------------+--------------+-----------+ </code></pre> <p>Any possible idea?</p> <p><strong>Remarks:</strong> Corrected myself</p> <pre><code>SELECT DISTINCT Name, u_country, u_postcode FROM user WHERE u_postcode NOT IN (SELECT d_postcode FROM data) </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.
 

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