Communities for your favorite technologies. Explore all Collectives
Stack Overflow for Teams is now called Stack Internal. Bring the best of human thought and AI automation together at your work.
Bring the best of human thought and AI automation together at your work. Learn more
Find centralized, trusted content and collaborate around the technologies you use most.
Stack Internal
Knowledge at work
Bring the best of human thought and AI automation together at your work.
This one has me stumpped.
I have 2 tables as so:
METERS id | startTime READINGS id | meter_id | readingTime
What I want to do is update the meters.startTime to the lowest matching readings.readingTime in 1 sql query.
meters.startTime
readings.readingTime
How do I do this?
Like this:
UPDATE Meters m INNER JOIN ( SELECT meter_id, MIN(reading_time) lowesttime FROM readings GROUP BY meter_id ) r ON m.id = r.meter_id SET m.starttime = r.lowesttime;
Add a comment
UPDATE METERS m SET startTime = (SELECT MIN(r.readingTime) FROM READINGS r WHERE r.meter_id = m.id) WHERE m.id = your_id
Start asking to get answers
Find the answer to your question by asking.
Explore related questions
See similar questions with these tags.