how to group by, and select from two tables, need two records for each given id

后端 未结 3 1100
暖寄归人
暖寄归人 2021-01-26 13:08

I am new to SQL query. Can you please help me with the following?

table 1 QuoteObservations:

id value quotePointId asOfTime 

table 2

3条回答
  •  无人及你
    2021-01-26 14:04

    SELECT
        QuoteObservations.id, 
        QuoteObservations.value, 
        QuoteObservations.asOfTime,
        QuotePoints.quoteType
    FROM
        QuoteObservations
        LEFT JOIN QuotePoints
        ON QuoteObservations.quotePointId = QuotePoints.id
    WHERE
        QuotePoints.quoteType = 1 
        OR QuotePoints.quoteType = 2
    ORDER BY 
        QuoteObservations.asOfTime DESC
    LIMIT 1;
    

提交回复
热议问题