Reputation: 358
I have two tables with the following descriptions:
record(record_id,min_index,max_index)
points(point_id,point_name,val1,val2,rank), point_id being on auto-increment
The min_index
,max_index
from record table points to the point_ids in the point table.
i.e. for a particular record, the respective points are >=min_index and <=max_index.
I need to merge these two tables such that, the final table resembles something like this
points(point_id,record_id,point_name,val1,val2,rank)
I know this is against the normalisation criteria, but this seems to work very well with the problem i have. I'm not sure on how to go about merging these two tables.
Upvotes: 1
Views: 144
Reputation: 4933
SELECT a.point_id,
b.record_id,
a.point_name,
a.val1,
a.val2,
a.rank
from points a , record b
where ((point_id>=min_index)and (point_id<=max_index))
Upvotes: 0
Reputation: 125865
Just join the tables using MySQL's BETWEEN ... AND ...
operator to specify your join criterion:
SELECT points.point_id,
record.record_id,
points.point_name,
points.val1,
points.val2,
points.rank
FROM points JOIN record ON
points.point_id BETWEEN record.min_index AND record.max_index
Upvotes: 2