Subject | Re: [firebird-support] Re: Optimizing a count query |
---|---|
Author | Helen Borrie |
Post date | 2008-10-12T13:07:21Z |
At 20:18 12/10/2008, you wrote:
SELECT
tjc.EXCESS_PAID,
tjc.JOB_CARD_ID,
tjc.TIME_START,
tjc.TIME_FINISH,
tjc....l
tjc.TIME_TAKEN,
tc.ADDRESS AS CLIENT_ADDRESS,
tc.SUBURB AS CLIENT_SUBURB,
tc.....,
tjc.ADVERT,
ti.COMPANY AS INSURER_COMPANY,
ti...,
tc.TBL_CLIENT.TITLE || ' ' || tc.SURNAME || ', ' || tjc.JOB_TYPE AS CAPTION,
...
tjc.COORDINATES,
tjc.VAT,
select
case
when (exists (select 1 from TBL_JOB_CARD_EMPLOYEE tjce
where tjce.JOB_CARD_ID = tjc.JOB_CARD_ID)) then 'Assigned'
else '--'
end
FROM
TBL_JOB_CARD tjc
LEFT OUTER JOIN TBL_CLIENT tc
ON (tc.CLIENT_ID = tjc.CLIENT_ID)
LEFT OUTER JOIN TBL_INSURER ti
ON (ti.INSURER_ID = tjc.INSURER_ID)
ORDER BY
tjc.JOB_CARD_ID DESC <--- make sure you have a DESC index on job_card_id
./heLen
>What I really want is this. The query must always show 1 masterDon't you mean "an output field"? I hope so.
>record irrespective of the number of detail records but there must
>also be a row that shows whether there are details records such as a
>boolean field. The count is not important. Does this make sense?
SELECT
tjc.EXCESS_PAID,
tjc.JOB_CARD_ID,
tjc.TIME_START,
tjc.TIME_FINISH,
tjc....l
tjc.TIME_TAKEN,
tc.ADDRESS AS CLIENT_ADDRESS,
tc.SUBURB AS CLIENT_SUBURB,
tc.....,
tjc.ADVERT,
ti.COMPANY AS INSURER_COMPANY,
ti...,
tc.TBL_CLIENT.TITLE || ' ' || tc.SURNAME || ', ' || tjc.JOB_TYPE AS CAPTION,
...
tjc.COORDINATES,
tjc.VAT,
select
case
when (exists (select 1 from TBL_JOB_CARD_EMPLOYEE tjce
where tjce.JOB_CARD_ID = tjc.JOB_CARD_ID)) then 'Assigned'
else '--'
end
FROM
TBL_JOB_CARD tjc
LEFT OUTER JOIN TBL_CLIENT tc
ON (tc.CLIENT_ID = tjc.CLIENT_ID)
LEFT OUTER JOIN TBL_INSURER ti
ON (ti.INSURER_ID = tjc.INSURER_ID)
ORDER BY
tjc.JOB_CARD_ID DESC <--- make sure you have a DESC index on job_card_id
./heLen