• expr@programming.dev
    link
    fedilink
    arrow-up
    1
    ·
    13 hours ago

    Heh yeah that’s pretty straightforward:

    SELECT a.*, COALESCE(b.some_col, 'some_default_val') as b_result
    FROM a LEFT JOIN b ON (a.id = b.id);
    

    This will produce at least 1 row for every row in a, and if a.id doesn’t match any b.id, the value of b_result will be 'some_default_val'.

    Not sure if that’s exactly what you were describing (since it was a little ambiguous), but that’s how I interpreted it.

    Ultimately it’s just a matter of investing a little time to learn it. It’s not fundamentally difficult or complex, even though you certainly can write very complex queries.

    • Valmond@lemmy.world
      link
      fedilink
      arrow-up
      1
      ·
      12 hours ago

      You make me think of that xkcd with two mineral experts, wildly overestimate what ordinary people know about their speciality 😅

      I have to do something like that sql like once every 2 years, so I tend to not invest enough, and then forget how it works. Give it some iterations and maybe I’ll be OK one day!

      Thanks for the solution!

      Edit only found the meme template:

      So you have to insert yourself: SQL, database specialist, SELECT, JOINS, COALESCE