sql - Postgresql Output column from another table -


i'm using postgresql, question querying a table that's in table , i'm having trouble one. in fact, i'm absolutely mentally blocked. i'll try define relations of tables as can.

i have table entry this:

entry

each of entries has group_id; when 'advanced' next stage, old entries marked is_active = false, , new assignment done, c & d advanced stages of & b.

i have table (which acts record keeper) , in storage_log_id refers to, storage_log table :

storage log

but have table, find out entries stored - storage table :

storage

to define problem properly. each entry has storage_log_id (but doesn't have yet), , storage_log has storage_id refer actual table , find storage label.

the sql query i'm trying should output one:

joined table

where actual storage label shown instead of log id.

this far i've done:

select e.id, e.group_id, e.name, e.stage, s.label operational.entry e, operational.storage_log sl, operational.storage s e.storage_log_id = sl.id , sl.storage_id = s.id 

but returns 3 rows, showing ones have seed_storage_log_id set; should able see without logs, , active ones. adding e.is_active = true condition makes results empty. so, yeah i'm stuck.

need help, guys!

use join select more tables:

here query:

select     e.id, e.group_id, e.name, e.stage, s.label    entry e left join    storage_log sl on     sl.id = e.storage_log_id left join     storage s on     sl.storage_id = s.id 

if wanna show rows strict relationship, remove left , use join show rows have relation in other table.

i hope helps.


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

thorough guide for profiling racket code -