|
If you normalize the structure of the database, you can do this with a single query. In other words, break out location1,location2,location3.... into its own table. A side benefit is that you can have location4, etc. without changing anything.
TABLE1 (your existing table)
ID_T1 (primary key)
...
TABLE2 (new location table)
ID_T1 (part 1 of primary key - foreign key to TABLE1)
SEQ_NUM (part 2 of primary key)
LOCATION
The query would look something like:
select table1.field1, table1.field2,...table2.location from table1, table2
where table1.id_t1 = table2.id_t1
and table2.location = 'LONDON'
order by table2.seq_num
I don't do a lot of MySQL, so I'm a little rusty on ANSI JOIN syntax. You may have to modify the above to conform to those rules. Not a big deal.
The "order by..." will sort by seq_num which will be 1,2,3,.... so that when 'LONDON' shows up in seq_num = 1 (the same as LOCATION1), it occurs before seq_num = 2, etc. The catch, of course, is that you have to modify your code for adding new entries to handle the second table.
__________________
It takes 2 points to draw a straight line, but at least 3 points to draw a conclusion.
|