Help!
I have 2 tables called log shelve
and shelve
.
Table old shelve
has columns old shelve
and new shelve
:
A | B
A | C
B | C
Table shelve
has columns shelve id
and shelve description
:
A | ONE RIGHT
B | ONE LEFT
C | TWO LEFT
I want to get data from those 2 tables, for example:
old shelve | shelve description | new shelve | shelve description |
---|---|---|---|
A | ONE RIGHT | B | ONE LEFT |
A | ONE RIGHT | C | TWO LEFT |
B | ONE LEFT | C | TWO LEFT |
Help me thanks
CodePudding user response:
You can join on shelve with different shelve_description.
SELECT
ls.old_shelve
,os.shelve_desc
,ls.new_shelve
,ns.shelve_desc
FROM log_shelve ls
LEFT JOIN shelve os ON ls.old_shelve = os.shelve_id
LEFT JOIN shelve ns ON ls.new_shelve = ns.shelve_id