1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

  2. Anuncie Aqui ! Entre em contato fdantas@4each.com.br

[SQL] Having trouble creating set-based query to create table data instead of doing it...

Discussão em 'Outras Linguagens' iniciado por Stack, Julho 28, 2021.

  1. Stack

    Stack Membro Participativo

    Given table settings with unique key of id+appId

    id appId name
    1 app1 setting1
    2 app1 setting2

    I have created new entries and the table looks like so

    id appId name
    1 app1 setting1
    2 app1 setting2
    3 app2 setting1
    4 app2 setting2

    Then given table user_settings that connects settings to a user

    userId settingsId
    1 1
    1 2
    2 1

    I need to add all of the new settings that were added for app2 to every user that currently has a setting for app1. The user should only get the settings that have matching names though.

    I don't know if that's clear so I'll say it this way as well: If the user has a setting of a given name for app1 then it should get the setting with the same name for app2.

    Is there a way to do this with set-based queries? Or do I have do this procedurally? I'm not great with much but basic SQL unfortunately.

    So the user_settings table should end up being

    userId settingsId
    1 1
    1 2
    2 1
    1 3
    1 4
    2 3

    Thank you for any help.

    Continue reading...

Compartilhe esta Página