-2

i have these table in database:

country:

id      country
------------------
1       USA
2       Brazil

and segment table:

id      country
------------------
1       USA
2       Brazil

i have a third table:

Id segment_id country_id

where segment_id is a foreign key of id in segment table

and country_id is a foreign key of id in country table

myquestion is:

how to select from the other table with inner join of the 3 tables,

i need to show the name of the country plus for every country show all the segments in a dropdown menu if anyone could help me

thank u

3 Answers3

0

you just try this

$sql = select * from third_table 
       inner join country on third_table.country_id = country.id
       inner join segment on third_table.segment_id = segment.id
$res = mysql_query($sql);

   'or'


   select * from TableA A 
   inner join TableB B on A.Column=B.Column 
   inner join TableC C on A.Column=C.Column
Andrew
  • 840
  • 3
  • 17
  • 43
  • 1
    [Please neither recommend using nor use `mysql_*()` functions](http://stackoverflow.com/q/12859942/2298301). They've been deprecated long ago and aren't a part of the build in PHP 7.0 and higher. – Dhruv Saxena May 09 '17 at 12:17
0
SELECT * 
FROM third_table t
INNER JOIN country c ON t.country_id = c.country_id
INNER JOIN segment s ON t.segment_id = s.segment_id
Ashu
  • 1,320
  • 2
  • 10
  • 24
0

try this query.. this will help you to create list

select countrysegments.id as countrysegmentsID, country.country as countryName,
segment.country as segmentName
from countrysegments 
       inner join country on countrysegments.country_id  = country.id
       inner join segment on countrysegments.segment_id = segment.id
Bilal Ahmed
  • 4,005
  • 3
  • 22
  • 42