-7

PHP

Tables are:

enter image description here

I have 2 tables, one of trips and the other is key table (index,type)
I want to receive all the names of the trips that the index of the trip type is 1 (output = Alexander)

I receive into variable "$Trip_Type" the user's choice and in addition I need to add to the query another condition of variable $Trip_Population, that has a key table for his values named "Population". How can I combine this in the query?

"Population" is a key table like "Types": 1. index, 2. Type. In addition there is a column "Population_Type" in table Trips. I need all in 1 query

I have this query and I need to add for this the Population condition:

$query = "SELECT trips.Trip_Num 
FROM trips JOIN trip_types ON trips.Trip_Type = trip_types.Type 
WHERE trip_types.type = " . $Trip_Type; 
  • Possible duplicate of [How can an SQL query return data from multiple tables](http://stackoverflow.com/questions/12475850/how-can-an-sql-query-return-data-from-multiple-tables) – piyushj Apr 28 '16 at 09:42
  • I receive into variable "$Trip_Type" the user's choice. How can I perform the query? – Yuval Asher Apr 28 '16 at 09:45
  • 1
    Would be nice to tell us what language do you use. Now you let us guess if it is php or what... Please edit your question and at least add respective tag – j.kaspar Apr 28 '16 at 09:51
  • php. In addition I need to add to the query another condition of variable $Trip_Population, that has a key table for his values named "Population". How can I combine this in the query? "Population" is a key table like "Types": 1. index, 2. Type. In addition there is a column "Population_Type" in table Trips. I need all in 1 query – Yuval Asher Apr 28 '16 at 17:47

3 Answers3

2
select t1.name 
from trips t1
inner join types t2 on t1.type =t2.type
Ankit Agrawal
  • 2,426
  • 1
  • 13
  • 27
0
$sql=
"SELECT t.name 
from trips t
JOIN types ty ON t.type = ty.type
WHERE ty.type = " . $Trip_Type;
DenseCrab
  • 1,273
  • 11
  • 22
0
SELECT a.name 
from trips a
JOIN types b ON t.type = a.type
WHERE b.type ='$Trip_Type'

I assume you are use php code to execute this query

Kunbero
  • 9
  • 2
  • 6
  • Tnx, using PHP. In addition I need to add to the query another condition of variable $Trip_Population, that has a key table for his values named "Population". How can I combine this in the query? – Yuval Asher Apr 28 '16 at 11:31