Hi in one of my project we are keeping the travel data of our clients in a table like this
id | user | country | travel_date |
------------------------------------------------------------------
1 | 12 | 4 | 2012-03-13 16:57:41 |
1 | 17 | 8 | 2012-03-13 16:57:41 |
1 | 12 | 5 | 2011-03-13 16:57:41 |
1 | 13 | 8 | 2011-03-13 16:57:41 |
1 | 11 | 3 | 2011-03-13 16:57:41 |
1 | 10 | 1 | 2013-03-13 16:57:41 |
1 | 12 | 1 | 2012-03-13 16:57:41 |
And we have a country table like this
id | name
------+----------
1 | India
2 | China
8 | Hongkong
3 | Singapore
Got a user table like this
id | Name
--------+----------
12 | name
17 | name 2
11 | name 3
10 | name 4
And we have to take the report like
- Which clients traveled in China and India 2012
The query is
SELECT DISTINCT user_id
FROM traveled_details
WHERE (country=1 OR country=2) AND YEAR(travel_date)=2012
Also we got a Clients table also. All the reports are working fine.
But we got a new requirement that need a report of Clients not traveled in China in 2012, or List of UN-traveled clients ever, or clients who need to travel in India
Is my table structure is enough for fetching such a query ? If yes I am bit confused with that query... Any one please help ?
user_id
andcountry_ìd
and add indexes on those columns.