0

Hi everyone i hope u are good.

I have an issue where i need to "fill" the values from table2 to table1, lemme explain better:

I have this table:

[TABLE1] (user_social_types)
id           type_info
0            facebook
1            twitter
2            youtube
3            instagram
4            linkedin

And this other table:

[TABLE2] (user_social_ref)
id           user_number            social_type           social_detail
1            452                    0                     asd123
2            452                    1                     123asd
3            452                    2                     a1s2d3
4            450                    0                     aaaaaa
5            450                    1                     bbbbbb
6            450                    2                     cccccc

I want to get ALL values from [TABLE1] and fill them with [TABLE2] values where user number is "450".

"pass_type" is a reference to [TABLE1] id.

I've tried this but it gave me the first values (user_number 452)

SELECT * FROM user_social_types
LEFT OUTER JOIN user_social_ref usr on user_social_types.id = usr.social_type
GROUP BY user_social_types.id


[RESULT]
id          type_info         usr.id          user_number           social_type      social_detail
0           facebook          1               452                   0                asd123
1           twitter           2               452                   1                123asd
2           youtube           3               452                   2                a1s2d3
3           instagram         null            null                  null             null
4           linkedin          null            null                  null             null

What im looking is for a way to do the same but get only values from user_number 452 because if i use

SELECT * FROM user_social_types
LEFT OUTER JOIN user_social_ref usr on user_social_types.id = usr.social_type
WHERE usr.user_number = "450"

I get only the values where [TABLE1] isnt empty and i need the null values

Thanks for taking your time to read this.

DEFALTUSER
  • 31
  • 1
  • 6

2 Answers2

0

Strawberry answered this question i just needed to change "WHERE" to "AND" and it worked. Since he doens't answer this question i'll mark my own as answer.

Thanks everyone.

DEFALTUSER
  • 31
  • 1
  • 6
0
SELECT
     ref.*
FROM user_social_ref AS ref
JOIN user_social_types AS types ON types.social_types = ref.id
WHERE ref.user_number = ?
GROUP BY ref.type_info //May not be nessecary
Jujubes
  • 424
  • 1
  • 6
  • 36