PHP mySQL - select unique value that not being used from dirrefent table
Posted
by apis17
on Stack Overflow
See other posts from Stack Overflow
or by apis17
Published on 2010-05-19T03:42:44Z
Indexed on
2010/05/19
6:10 UTC
Read the original article
Hit count: 297
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
- I want to use grouping to filter postcode and make Name3 and Name4 as different rows.
For example:
+-----------------------+--------------+-----------+
| Name | u_country | u_postcode|
+-----------------------+--------------+-----------+
| Name2 | Country5 | 5555 |
| Name3 | | 6666 |
| Name4 | Country6 | 6666 |
+-----------------------+--------------+-----------+
Any possible idea?
© Stack Overflow or respective owner