RE: [PHP-DB] SELECT syntax
| From: | Toby Hart Dyke | Date: | Wed, 12 Oct 2011 20:08:05 +0000 |
| Subject: | RE: [PHP-DB] SELECT syntax | ||
| References: | 1 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-48038@lists.php.net to get a copy of this message | ||
Not terribly elegant, but this should work:
SELECT
trivia_answer_1 AS trivia_answer FROM Bible_trivia
WHERE answer=1
UNION
SELECT trivia_answer_2 AS trivia_answer FROM Bible_trivia
WHERE answer=2
UNION
SELECT trivia_answer_3 AS trivia_answer FROM Bible_trivia
WHERE answer=3
UNION
SELECT trivia_answer_4 AS trivia_answer FROM Bible_trivia
WHERE answer=4;
I have to say that it's likely that your design may not be the most optimal. What happens if
you want 5 answers? Or 6?
Toby
-----Original Message-----
From: Ron Piggott [mailto:ron.piggott@actsministries.org]
Sent: Wednesday, October 12, 2011 3:25 PM
To: php-db@lists.php.net
Subject: [PHP-DB] SELECT syntax
In my Bible_Trivia table I have the columns
trivia_answer_1, trivia_answer_2, trivia_answer_3,
trivia_answer_4, answer
answer is an integer always with a value of 1 to 4. Is there a way to use the value of
answer to only select the correct trivia answer?
This doesn’t work, but this is the idea I am trying to achieve:
SELECT trivia_answer_answer` FROM Bible_trivia`
Thanks in advance,
Ron
www.TheVerseOfTheDay.info