Reputation: 397
I have these two SELECT statements:
SELECT Termin FROM crSpielTermine WHERE Status = 1
and this
SELECT TerminID FROM crSpielTermine WHERE Termin > ".$AlterTermin." ORDER BY Termin LIMIT 1
Right now, the first select supplies me $AlterTermin
which I'm using in the
second statement.
Can I combine these two statements and if yes, how I'm going to do this?
Upvotes: 0
Views: 85
Reputation: 14992
Supposing that your first select returns only a single item, you'd have something like that:
SELECT TerminID
FROM crSpielTermine
WHERE Termin > (SELECT Termin FROM crSpielTermine WHERE Status = 1)
ORDER BY Termin
LIMIT 1
Or this just to make sure it returns only one item
SELECT TerminID
FROM crSpielTermine
WHERE Termin > (SELECT Termin FROM crSpielTermine WHERE Status = 1 LIMIT 1)
ORDER BY Termin
LIMIT 1
Upvotes: 3
Reputation: 96
You may use sub-query as follows which will give same result :
SELECT TerminID FROM crSpielTermine
WHERE Termin > (SELECT Termin FROM crSpielTermine WHERE Status = 1)
ORDER BY Termin LIMIT 1
Upvotes: 2