Reputation: 3183
I have 3 tables, I need advice on how to get data from them.
details_varchar
details_int
details_date
each of them have value_id
[Int] and value_name
[value_name type varies as per table name - Varchar, Int, Date]
value_id
will be present in any one of the 3 tables. i.e ID from 1 to n are stored in these tables according to their Data Types. If value_id = 1 and value_name[type] = int then it stores in details_int table.select value_name from 3 tables[may appear in any one of the table] where value_id = '[I have this value stored in a variable]'
UNION
- but all the table needs to have same column type.
JOINS
- All the fields should be connected.[I guess]
Upvotes: 0
Views: 40
Reputation: 10996
SELECT value_name
FROM ( SELECT value_name
FROM details_varchar
WHERE value_id = {$int_value_id}
UNION ALL
SELECT value_name
FROM details_int
WHERE value_id = {$int_value_id}
UNION ALL
SELECT value_name
FROM details_date
WHERE value_id = {$int_value_id}) AS h
This should give you what you want?
Upvotes: 1