MySQL: Get results given a condition -


I have a table that looks like this:

target_id || Countrycode

5 ----------- || ------- US ----

5 -------- --- --- ------- CA --- < H1> 2 ---------- || ------- FR ----

3 ---------- || ------- SP ----

3 ---------- || ------- FR ----

and the other table that looks like this:

target_id || Area_name

5 ----------- || --- North America

2 ----------- || - --- France ------

3 ----------- || As you can see, table 2 contains location and target_ids, whereas in Table 1, in the case of North America, this target is up to 5 , Which is Canada and America, on the other hand is target_ID of France, 2, and some are target_id of Europe 3, which includes France and Spain.

What I would like to do through MySQL, is to get a table of goal, country code, country_name but for countries only, this means only for goal_ids of Table 1, which are in only one line (For example, we know that FR is a country because number 2 is only in the FR, and we know that 3 represents an area because there are both Spain and France affiliate). Is it possible to do this via MySQL or I need two questions and PHP?

Thank you!

select
  t1.target_id, t1.country_code, t2.region_name from table 1 t1 JOIN T1.target_id = t2.target_id on table T2 (Select COUNT (*) Table 1 to T3 WHERE t3.target_id = T1.target_id) = 1   

Table 1 is the one with the country code, table2 is with the name of this field.

Comments

Popular posts from this blog

mysql - BLOB/TEXT column 'value' used in key specification without a key length -

c# - Using Vici cool Storage with monodroid -

python - referencing a variable in another function? -