'MySQL Joining two tables replacing ID with user name

I have a problem with JOIN, INNER JOIN based on two tables as below I was trying to JOIN them with no result actually (got mysql errors)and after few hours i give up I belive there must be a solution but i think now that i don't understant JOIN - INNER JOIN - or other kind of needed join type. Is there someone who could help me with this query?

Table 1 - jawe_wpdatatable_8 :

uzytkownik column2 column3
2 some data some data
1 some data some data
2 some data some data
2 some data some data
2 some data some data

table 2 - jawe_users:

ID user_nicename other not important columns...
1 bart
2 asia
3 bry1

the result I expect should be like this:

mysql expected result

uzytkownik column2 column3
asia some data some data
bart some data some data
asia some data some data
asia some data some data
asia some data some data

I want to replace 2,1 and other numbers of 'uzytkownik' with coresponding with them user_nicename

I was trying to figure it out basing on MYSQL: join multiple tables - replace multiple userID's with user names With no result. I don't get it.

Tanks in advance for any help. Best regards.


OK. so I figured it out and for me working query (on real table) is

SELECT r.data,
       r.nrpartii,
       r.nazwadzianiny,
       r.skladdzianiny,
       r.nazwamaszyny,
       r.rzad,
       r.nrmaszyny,
       r.starynrmaszyny,
       r.nruiglenia,
       r.wydzigla,
       r.waga,
       r.uwagipredkoscmaszyny,
       u1.user_nicename
FROM jawe_wpdatatable_8 AS r
inner join jawe_users as u1 on u1.ID = r.uzytkownik

Tested in sql console



Solution 1:[1]

I think you are looking for a simple join:

SELECT 
  j.`user_nicename` AS uzytkownik, 
  k.`column2`,
  k.`column3`
FROM
  `jawe_users` j 
  JOIN `jawe_wpdatatable_8` k 
    ON k.`uzytkownik` = j.`id` 
   

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Asgar