Updates : Please see below
i have table: data
+-----------------------+--------------+-----------+
| State | d_country | d_postcode|
+-----------------------+--------------+-----------+
| State1 | Country1 | 1111 |
| State2 | Country2 | 2222 |
| State3 | Country3 | 3333 |
| State4 | Country4 | 4444 |
+-----------------------+--------------+-----------+
And another table: user
+-----------------------+--------------+-----------+
| Name | u_country | u_postcode|
+-----------------------+--------------+-----------+
| Name1 | Country3 | 3333 |
| Name2 | Country5 | 5555 |
| Name3 | | 6666 |
| Name4 | Country6 | 6666 |
| Name5 | Country6 | 6666 |
+-----------------------+--------------+-----------+
What SQL should i use to:
Determine the number (count) of country that are not listed on table data.
For example
u_postcode
is not listed in
d_postcode
is 5555 and 6666. It will return 2.
List down name and what country not available in table data yet.
Updates
For example:
+-----------------------+--------------+-----------+
| Name | u_country | u_postcode|
+-----------------------+--------------+-----------+
| Name2 | Country5 | 5555 |
| Name3 | | 6666 |
| Name4 | Country6 | 6666 |
+-----------------------+--------------+-----------+
Any possible idea?
Remarks: Corrected myself
SELECT DISTINCT Name, u_country, u_postcode FROM user
WHERE u_postcode NOT IN (SELECT d_postcode FROM data)
Try this.
SELECT Name, u_country, u_postcode FROM user
WHERE u_postcode NOT IN (SELECT d_postcode FROM data)
Hope it helps
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.