From: | Grzegorz Jaśkiewicz <gryzman(at)gmail(dot)com> |
---|---|
To: | Terry <td3201(at)gmail(dot)com> |
Cc: | PostgreSQL <pgsql-general(at)postgresql(dot)org> |
Subject: | Re: join from multiple tables |
Date: | 2010-03-05 09:14:23 |
Message-ID: | 2f4958ff1003050114o6837e86dxb262c57a1ec917c6@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
altho not an answer to your question, you might want to start using table
name aliases, to make queries more readable.
so instead of:
SELECT dsclient_logs.ev_id,dsclient_
logs.type,to_timestamp(dsclient_logs.ev_time)
as
timestamp,dsclient_logs.category,dsclient_logs.error,dsclient_logs.ev_text,dsclient_logs.userid,dsclient_logs.ex_long,dsclient_logs.client_ex_long,dsclient_logs.ex_text,backup_sets.set_name,customer.company_name,customer.account_num
FROM dsclient_logs
INNER JOIN connection_log ON dsclient_logs.ex_long =
connection_log.session_id AND dsclient_logs.userid =
connection_log.dsbox_snum
INNER JOIN backup_sets ON connection_log.set_id = backup_sets.set_id
INNER JOIN customer ON connection_log.account_num = customer.account_num
ORDER BY dsclient_logs.ev_id desc LIMIT 100
you would do:
SELECT dsl.*, sb.set_name, c.company_name, c.account_num
FROM dsclient_logs dsl
INNER JOIN connection_log cl ON dsl.ex_long = cl.session_id AND dsl.userid =
cl.dsbox_snum
INNER JOIN backup_sets bs ON cl.set_id = bs.set_id
INNER JOIN customer c ON cl.account_num = c.account_num
ORDER BY dsl.ev_id desc LIMIT 100
etc.
From | Date | Subject | |
---|---|---|---|
Next Message | Richard Huxton | 2010-03-05 09:14:52 | Re: Restore Data Encountered the ERROR: literal carriage return found in data Error |
Previous Message | Albe Laurenz | 2010-03-05 09:12:14 | Re: ERROR: row is too big: size 8176, maximum size 8160 |