简体   繁体   中英

SELECT STATEMENT QUERY POSTGRES

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM