I have the following table structure:
Table: Table1
Columns: Entry, Tag1, Tag2, Tag3, Tag4.
(Entry is the row number, i.e. 1, 2, 3, etc.)
If I want to combine all tags into 1 in a single query, I'd do the following:
Select Tag1 FROM Table1
UNION ALL
Select Tag2 FROM Table1
UNION ALL
Select Tag3 FROM Table1
UNION ALL
Select Tag4 FROM Table1;
But let's say I want to do the above query but only on the entries where Entry is between 100 and 200, I'd use the following code:
Select Tag1 FROM Table1
WHERE Entry >= 100 AND Entry <= 200
UNION ALL
Select Tag2 FROM Table1
WHERE Entry >= 100 AND Entry <= 200
UNION ALL
Select Tag3 FROM Table1
WHERE Entry >= 100 AND Entry <= 200
UNION ALL
Select Tag4 FROM Table1
WHERE Entry >= 100 AND Entry <= 200;
Is there any way I can simply the second query without repeating "WHERE Entry >= 100 AND Entry <= 200" so many times? In other words, if I had to do the same sort of operation but had 100 columns of tags that I need to combine into a single column and has to be between 2 distinct entries in a table, is it possible to shorten the query significantly?
Aucun commentaire:
Enregistrer un commentaire