php - mysql multiple row values in where condition on a single table -
this question exact duplicate of:
i had unique requirement. don't know it's table structure problem or thing else, need solution output either structure change or query change.
i had table containing dynamic values of 2 fields of single user. single user can have multiple records of types.
example tables below
table name: tbl_parameters
parameter_id parameter_name 1 current location 2 booked location 3 room type
table name: tbl_paramter_data
id(auto_increment) user_id parameter_id parameter_value 1 10 1 hyderabad 2 10 2 delhi 3 10 3 deluxe room 4 11 1 hyderabad 5 11 2 bombay 6 11 3 a/c room 7 12 1 delhi 8 12 2 bombay 9 12 3 deluxe room 10 13 1 hyderabad 11 13 2 delhi 12 13 3 single room
the above 2 tables. hotel booking table. user can book hotel room india. so, stored in 2 different table. 1st table contain type of parameters need store parameter_id. 2nd table contain parameters values of each user booked, room booked , remaining data. there other parameters also. **the no of parameters dynamic. there not fixed no of parameters, that's reason maintained separate table tbl_parameters.
my question how can data of
- who users booked rooms "hyderabad" in "bombay" hotel?
- who users booked "deluxe rooms" "delhi" in "bombay" hotel?
how write query fetch above data existing table(tbl_parameter_data)?
or shall need change table structure or way storing?
i think trick. (not tested yet) depends on how complex query (each paramater needs new joins)
select user_id tbl_parameter_data p1 join tbl_parameters pa1 on p1.parameter_id = pa1.parameter_id join (tbl_parameter_data p2 join tbl_parameters pa2 on p2.parameter_id = pa2.parameter_id) on p1.user_id=p2.user_id pa1.parameter_name = "current location" , p1.parameter_value = "hydrabad" , pa2.parameter_name = "booked location" , p2.parameter_value = "bombay"
old version:
select user_id tbl_parameter_data p1 join join tbl_parameter_data p2 on p1.user_id=p2.user_id p1.parameter_id = 1 , p1.parameter_value = "hydrabad" , p2.parameter_id = 2 , p2.parameter_value = "bombay"
Comments
Post a Comment