Access SQL Matching Join then Like Join - sql

Good Afternoon,
Is is possible in MS Access SQL to firstly try a matching left join and if there is no match then to a like/contains join?
Currently my like join looks like this
SELECT
[tbl_Area_lkup].[Area],
[tbl_Area_lkup].[Sub Area],
[tbl_Area_lkup].[PageTrimmed] AS [Page lkup],
qry_AdviserPages_Step1.PageTrimmed AS [Trimmed Page],
qry_AdviserPages_Step1.Page AS Page,
qry_AdviserPages_Step1.Date, IIf([tbl_Medium_lkup].[mediumgrp] Is Null,"CHECK",[tbl_Medium_lkup].[mediumgrp]) AS Medium,
qry_AdviserPages_Step1.Hostname,
qry_AdviserPages_Step1.Users,
qry_AdviserPages_Step1.Sessions,
qry_AdviserPages_Step1.Pageviews
FROM (qry_AdviserPages_Step1
LEFT JOIN tbl_Area_lkup ON [qry_AdviserPages_Step1].[PageTrimmed] Like '*' & [tbl_Area_lkup].[PageTrimmed] & '*')
LEFT JOIN tbl_Medium_lkup ON qry_AdviserPages_Step1.Medium = tbl_Medium_lkup.Medium
ORDER BY 2;
What I would like to do is an = join on the same Columns but if there is no match then to carry out the above join.
Any pointers would be great.
Thanks.

Related

Nesting multiple same select queries and reuse without second round trip to database

I am having a rows with two different IDs in database. Now I am trying to show two different data columns in one row, I tried something like this:
SELECT
[dbo].[fnHexToNumber]([Participant].[Stake]) AS [PlayerStake],
(SELECT [dbo].[fnHexToNumber]([Stake])
FROM [dbo].[Participant_Complete]
WHERE [ParticipantId] = [Fold].[HouseParticipantId]) AS [HouseStake],
([dbo].[fnHexToNumber]([Participant].[Stake]) + [dbo].[fnHexToNumber]([C].[RunningWinLoss])) AS [PlayerStakeAfterRound],
(SELECT [dbo].[fnHexToNumber]([Stake])
FROM [dbo].[Participant_Complete]
WHERE [ParticipantId] = [Fold].[HouseParticipantId]) - [dbo].[fnHexToNumber]([C].[RunningWinLoss]) AS [HouseStakeAfterRound]
FROM
[dbo].[Round_Complete] AS [C]
INNER JOIN
[dbo].[Fold_Complete] AS [Fold] ON [Fold].[Id] = [C].[Id]
INNER JOIN
[dbo].[Participant_Complete] AS [Participant] ON [Participant].[ParticipantId] = [Fold].[PlayerParticipantId]
This works, but as you can see it will do two trips to database for same nested select. How can I make this only one round trip?
You are referring to the subqueries. That is not a "round trip to the database", which usually refers to an application calling a query.
All the square braces make the query hard to read, but you can fix this using apply:
SELECT [dbo].[fnHexToNumber](p.[Stake]) AS PlayerStake,
h.HouseStake,
([dbo].[fnHexToNumber](p.[Stake]) + [dbo].[fnHexToNumber]([C].RunningWinLoss)) AS PlayerStakeAfterRound,
(h.HouseStake - [dbo].fnHexToNumber(C.RunningWinLoss)) AS HouseStakeAfterRound
FROM [dbo].[Round_Complete] c JOIN
[dbo].[Fold_Complete] f
ON f.[Id] = c.[Id] JOIN
[dbo].[Participant_Complete] pc
ON px.[ParticipantId] = f.[PlayerParticipantId] OUTER APPLY
(SELECT [dbo].[fnHexToNumber]([Stake]) as HouseStake
FROM [dbo].[Participant_Complete] pch
WHERE pch.ParticipantId = f.HouseParticipantId
) h
Just join the same table a second time instead of pulling the data as sub-queries.
Also, you only need brackets around names if the names contain a space (which is bad practice in general). If the names don't have a space, the brackets are totally extraneous.
SELECT
dbo.fnHexToNumber(Participant.Stake) AS PlayerStake,
dbo.fnHexToNumber(p.Stake) as HouseStake,
(dbo.fnHexToNumber(Participant.Stake) + dbo.fnHexToNumber(C.RunningWinLoss)) AS PlayerStakeAfterRound,
dbo.fnHexToNumber(p.Stake) - dbo.fnHexToNumber(c.RunningWinLoss) as HouseStakeAfterRound
FROM dbo.Round_Complete AS C
INNER JOIN dbo.Fold_Complete AS Fold
ON Fold.Id = C.Id
INNER JOIN dbo.Participant_Complete AS Participant
ON Participant.ParticipantId = Fold.PlayerParticipantId
INNER JOIN dbo.Participant_Complete AS p
ON p.ParticipantId = Fold.HouseParticipantId

Can this Oracle SQL query be simplified?

Is there a way I can write this better? The way it's currently written is taking a long time to pull the data. The results of the data also repeat data multiple lines with the same info. Any suggestions? I tried changing the join clauses but that didn't help much. I'm not sure what else I could use to shorten the query to make it run smoother and get better results.
select
PT_IDENTIFIER.PT_IDENTIFIER_VALUE,
PT_STUDY.FK_SOCRD_ID,
patient.PTLASTNAME || ', ' || patient.PTFIRSTNAME as "Patient name",
patient.DOB,
PT_STUDY.SUBJECT_NUMBER,
CR_imaging.CR_IMAGING as "CR_Imaging",
CR_imaging.CR_IMAGING_SPEC,
CR_IMAGING.CR_IMAGING_DT,
CR_imaging.CR_IMG_SITE,
CR_IMAGING.CR_IMG_SITE_SPEC,
CR_IMAGING.CR_IMAGING_CT,
CR_IMAGING.CR_IMAGING_CN,
CR_IMAGING.CR_IMAGING_CM,
CR_WORKUPPROC.CR_WORKUPPROC,
CR_WORKUPPROC.CR_WORKUPPROC_DT,
CR_DISEASE_HISTORY.CR_DISEASE_HISTORY,
CR_DISEASE_HISTORY.CR_DISEASE_HISTORY_DT,
CR_MDT.CR_MDT_DT,
CR_MDT.CR_MDT_DIAG,
CR_MDT.CR_MDT_PHYS,
CR_MDT.CR_MDT_PRESENTED,
CR_MDT.CR_MDT_HISTTYPE,
CR_MDT.CR_MDT_STAGE,
CR_MDT.CR_MDT_CT,
CR_MDT.CR_MDT_CN,
CR_MDT.CR_MDT_CM,
CR_MDT.CR_MDT_PT,
CR_MDT.CR_MDT_PN,
CR_MDT.CR_MDT_PM,
CR_MDT.CR_MDT_LOOKBACK,
CR_MDT_PATH_REVIEW_DT,
CR_MDT_PATH_REVIEW,
CR_MDT_RECOM.CR_MDT_RECOM,
CR_MDT_RECOM.CR_MDT_RECOM_SPEC,
TUMORSITE.DIAGNOSIS_DT,
TUMORSITE.TUMORSITE,
TUMORSITE.TUMORSITE_SPEC,
TUMORSITE.RECURRENCE_DT,
TUMORSITE.RECURRENCE_DT_EST,
TUMORSITE.METASTASIS_DT,
TUMORSITE.METASTASIS_DT_EST,
CR_SYSTEMIC.CR_AGENT,
CR_SYSTEMIC.CR_AGENT_SPEC,
CR_SYSTEMIC.CR_SYS_CYCLE,
CR_SYSTEMIC.CR_SYS_DOSE_DAY,
CR_SYSTEMIC.CR_SYS_DOSE_TOTAL,
CR_SYSTEMIC.CR_SYS_START_DT,
CR_SYSTEMIC.CR_SYS_START_DT_EST,
CR_SYSTEMIC.CR_SYS_END_DT,
CR_SYSTEMIC.CR_SYS_END_DT_EST,
CR_RADIATION.CR_RAD_START_DT,
CR_RADIATION.CR_RAD_START_DT_EST,
CR_RADIATION.CR_RAD_END_DT,
CR_RADIATION.CR_RAD_END_DT_EST,
CR_RADIATION.CR_RAD_PHYS,
CR_RADIATION.CR_RAD_DOSE,
CR_RADIATION.CR_RAD_NOTES,
CR_SURGERY.CR_SURGERY_DT,
CR_SURGERY.CR_SURGERY,
CR_SURGERY.CR_SURGEON,
CR_SURGERY.CR_SURGERY_DT_EST,
CR_SURGERY.CR_SURG_APPROACH,
CR_SURGERY.CR_SURGERY_SPEC,
CR_PATHOLOGY.CR_SURG_PT,
CR_PATHOLOGY.CR_SURG_PN,
CR_PATHOLOGY.CR_SURG_PM,
CR_PATHOLOGY.CR_SURG_HISTTYPE,
CR_PATHOLOGY.CR_SURG_TME,
CR_PATHOLOGY.CR_SURG_TME_REASON,
CR_PATHOLOGY.CR_SURG_TME_REASON_SPEC,
CR_PATHOLOGY.CR_SURG_DISTAL,
CR_PATHOLOGY.CR_SURG_MSI,
CR_PATHOLOGY.CR_SURG_CRM,
CR_PATHOLOGY.CR_SURG_PROX_DIST,
FU_STATUS.FU_DT,
FU_STATUS.FU_STATUS,
FU_STATUS.FU_CANCERSTATUS,
CR_LAB.CR_LAB_DT,
CR_LAB_TUMORMARKER.CR_LAB_TUMORMARKER,
CR_DISEASE_HISTORY.CR_FAM_HISTORY,
CR_GENTEST.CR_GENTEST,
CR_GENTEST.CR_GENTEST_SPEC,
CR_GENTEST.CR_GENTEST_DT,
CR_GENTEST.CR_GENTEST_RESULT
from
CR_IMAGING
left join patient
on CR_IMAGING.fk_SOCRD_ID=patient.SOCRD_ID
left join PT_IDENTIFIER
on patient.socrd_id=PT_IDENTIFIER.FK_SOCRD_ID
left join PT_STUDY
on patient.SOCRD_ID=PT_STUDY.FK_SOCRD_ID
left join CR_DISEASE_HISTORY
on CR_DISEASE_HISTORY.FK_SOCRD_ID=patient.SOCRD_ID
left join CR_MDT
on CR_MDT.FK_SOCRD_ID=PATIENT.SOCRD_ID
left join CR_MDT_RECOM
on CR_MDT.CR_MDT_ID=CR_MDT_RECOM.FK_CR_MDT_ID
left join tumorsite
on tumorsite.FK_SOCRD_ID=PATIENT.SOCRD_ID
left join CR_SYSTEMIC
on CR_SYSTEMIC.FK_SOCRD_ID=PATIENT.SOCRD_ID
left join CR_RADIATION
on CR_RADIATION.FK_SOCRD_ID=PATIENT.SOCRD_ID
left join CR_SURGERY
on CR_SURGERY.FK_SOCRD_ID=PATIENT.SOCRD_ID
LEFT JOIN FU_STATUS
ON FU_STATUS.FK_SOCRD_ID=PATIENT.SOCRD_ID
LEFT JOIN CR_LAB
ON CR_LAB.FK_SOCRD_ID=PATIENT.SOCRD_ID
LEFT JOIN CR_LAB_TUMORMARKER
ON CR_LAB_TUMORMARKER.FK_CR_LAB_ID=CR_LAB.CR_LAB_ID
left join CR_PATHOLOGY
on CR_PATHOLOGY.FK_CR_SURGERY_ID=CR_SURGERY.CR_SURGERY_ID,
cr_workupproc CR_WORKUPPROC
where cr_workupproc.FK_SOCRD_ID=patient.SOCRD_ID
and CR_DISEASE_HISTORY.FK_SOCRD_ID=patient.SOCRD_ID
and PT_STUDY=3
GROUP BY PT_STUDY.SUBJECT_NUMBER,
patient.PTLASTNAME, patient.PTFIRSTNAME,
CR_imaging.CR_IMAGING,
CR_IMAGING.CR_IMAGING_DT, patient.DOB,
CR_imaging.CR_IMG_SITE,
CR_IMAGING.CR_IMG_SITE_SPEC,
CR_imaging.CR_IMAGING_SPEC,
CR_IMAGING.CR_IMAGING_CT,
CR_IMAGING.CR_IMAGING_CN,
CR_IMAGING.CR_IMAGING_CM,
CR_WORKUPPROC.CR_WORKUPPROC,
CR_WORKUPPROC.CR_WORKUPPROC_DT,
CR_DISEASE_HISTORY.CR_DISEASE_HISTORY,
CR_DISEASE_HISTORY.CR_DISEASE_HISTORY_DT,
CR_MDT_RECOM.CR_MDT_RECOM,
CR_MDT.CR_MDT_DT,
CR_MDT.CR_MDT_PHYS,
CR_MDT.CR_MDT_PRESENTED,
CR_MDT.CR_MDT_HISTTYPE,
CR_MDT.CR_MDT_STAGE,
CR_MDT.CR_MDT_CT,
CR_MDT.CR_MDT_CN,
CR_MDT.CR_MDT_CM,
CR_MDT.CR_MDT_LOOKBACK,
CR_MDT.CR_MDT_PT,
CR_MDT.CR_MDT_PN,
CR_MDT.CR_MDT_PM,
CR_MDT_PATH_REVIEW_DT,
CR_MDT_PATH_REVIEW,
TUMORSITE.TUMORSITE,
TUMORSITE.TUMORSITE_SPEC,
TUMORSITE.RECURRENCE_DT,
TUMORSITE.RECURRENCE_DT_EST,
TUMORSITE.METASTASIS_DT,
TUMORSITE.METASTASIS_DT_EST,
CR_SYSTEMIC.CR_AGENT,
CR_SYSTEMIC.CR_AGENT_SPEC,
CR_SYSTEMIC.CR_SYS_CYCLE,
CR_SYSTEMIC.CR_SYS_DOSE_DAY,
CR_SYSTEMIC.CR_SYS_DOSE_TOTAL,
CR_SYSTEMIC.CR_SYS_START_DT,
CR_SYSTEMIC.CR_SYS_START_DT_EST,
CR_SYSTEMIC.CR_SYS_END_DT,
CR_SYSTEMIC.CR_SYS_END_DT_EST,
CR_RADIATION.CR_RAD_START_DT,
CR_RADIATION.CR_RAD_START_DT_EST,
CR_RADIATION.CR_RAD_END_DT,
CR_RADIATION.CR_RAD_END_DT_EST,
CR_RADIATION.CR_RAD_PHYS,
CR_RADIATION.CR_RAD_DOSE,
CR_RADIATION.CR_RAD_NOTES,
CR_SURGERY.CR_SURGERY_DT,
CR_SURGERY.CR_SURGERY,
CR_SURGERY.CR_SURGEON,
CR_SURGERY.CR_SURGERY_DT_EST,
CR_SURGERY.CR_SURG_APPROACH,
CR_PATHOLOGY.CR_SURG_PT,
CR_PATHOLOGY.CR_SURG_PN,
CR_PATHOLOGY.CR_SURG_PM,
CR_PATHOLOGY.CR_SURG_HISTTYPE,
CR_PATHOLOGY.CR_SURG_TME,
CR_PATHOLOGY.CR_SURG_TME_REASON,
CR_PATHOLOGY.CR_SURG_TME_REASON_SPEC,
CR_PATHOLOGY.CR_SURG_DISTAL,
CR_PATHOLOGY.CR_SURG_MSI,
CR_PATHOLOGY.CR_SURG_CRM,
CR_PATHOLOGY.CR_SURG_PROX_DIST,
PT_STUDY.FK_SOCRD_ID,
CR_MDT.CR_MDT_DIAG,
FU_STATUS.FU_DT,
FU_STATUS.FU_STATUS,
FU_STATUS.FU_CANCERSTATUS,
PT_IDENTIFIER_VALUE,
CR_MDT_RECOM.CR_MDT_RECOM_SPEC,
TUMORSITE.DIAGNOSIS_DT,
CR_LAB.CR_LAB_DT,
CR_LAB_TUMORMARKER.CR_LAB_TUMORMARKER,
CR_SURGERY.CR_SURGERY_SPEC
difficult to say without knowing more about your tables and data.
Its probably better (if only for readability) not to mix your join methods, so i'd convert the inner join to
inner join cr_workupproc on cr_workupproc.FK_SOCRD_ID=patient.SOCRD_ID
and CR_DISEASE_HISTORY.FK_SOCRD_ID
your only filter in the query is
and PT_STUDY=3
but pt_study seems to be a table or is this also a column on some table? if so its probably better to be explicit as to where it is with a table qualifier.
If this is not a column on cr_imaging table, then you probably need to check your table order, as you are probably doing a number of full table scans.
Also you should get an explain plan for the query to see what it is doing which may help you to optimise the query.

Sql Inner join query on condition when specific value

I have following query:
SELECT Art.Id, Art.Nummer, Art.Serie, Art.EANBarcode, Art.Preis, Art.Volumen, Art.Vater, Art.Name, Art.Amazon, Kat.Name, Subkat.Name, Subsubkat.Name FROM
tbArtikel As Art
INNER JOIN tbKategorie As Kat ON Art.FK_Kategorie_ID=Kat.Id
INNER JOIN tbSubkategorie As Subkat ON Art.FK_SubKategorie_ID=Subkat.Id
INNER JOIN tbSubsubkategorie As Subsubkat ON Art.FK_SubSubKategorie_ID=Subsubkat.Id
WHERE RIGHT(Art.Nummer,2)='.1'
The situation is that Art.FK_SubSubKategorie_ID can be null (developers did that setting 0 instead of null) - knows that bad habit but how it is. However i want to make if there is really 0 for Art.FK_SubSubKategorie_ID i want to take that record and for Subsubkat.Name just put empty string. Hope got my point.
Additional question if possible(PS):
Is there any diffrence in where condition if i do:
WHERE RIGHT(Art.Nummer,2)='.1'
WHERE Art.Nummer LIKE '%.1'
or even:
WHERE NOT RIGHT(Art.Nummer,2)='.1'
WHERE Art.Nummer NOT LIKE '%.1'
I know that like working with indexes, but i am just talking about whether in this case both will work and search exactly the same? I am using that to get specific articles.
Try this;
SELECT Art.Id, Art.Nummer, Art.Serie,
Art.EANBarcode, Art.Preis, Art.Volumen, Art.Vater, Art.Name,
Art.Amazon, Kat.Name, Subkat.Name, ISNULL(Subsubkat.Name,'')
FROM
tbArtikel As Art
INNER JOIN tbKategorie As Kat ON Art.FK_Kategorie_ID=Kat.Id
INNER JOIN tbSubkategorie As Subkat ON Art.FK_SubKategorie_ID=Subkat.Id
LEFT OUTER JOIN tbSubsubkategorie As Subsubkat ON Art.FK_SubSubKategorie_ID=Subsubkat.Id
WHERE RIGHT(Art.Nummer,2)='.1'

Ignore null values in select statement

I'm trying to retrieve a list of components via my computer_system, BUT if a computer system's graphics card is set to null (I.e. It has an onboard), the row isn't returned by my select statement.
I've been trying to use COALESCE without results. I've also tried with and OR in my WHERE clause, which then just returns my computer system with all different kinds of graphic cards.
Relevant code:
SELECT
computer_system.cs_id,
computer_system.cs_name,
motherboard.name,
motherboard.price,
cpu.name,
cpu.price,
gfx.name,
gfx.price
FROM
public.computer_case ,
public.computer_system,
public.cpu,
public.gfx,
public.motherboard,
public.ram
WHERE
computer_system.cs_ram = ram.ram_id AND
computer_system.cs_cpu = cpu.cpu_id AND
computer_system.cs_mb = motherboard.mb_id AND
computer_system.cs_case = computer_case.case_id AND
computer_system.cs_gfx = gfx.gfx_id; <-- ( OR computer_system.cs_gfx IS NULL)
Returns:
1;"Computer1";"Fractal Design"; 721.00; "MSI Z87"; 982.00; "Core i7 I7-4770K "; 2147.00; "Crucial Gamer"; 1253.00; "ASUS GTX780";3328.00
Should I use Joins? Is there no easy way to say return the requested row, even if there's a bloody NULL value. Been struggling with this for at least 2 hours.
Tables will be posted if needed.
EDIT: It should return a second row:
2;"Computer2";"Fractal Design"; 721.00; "MSI Z87"; 982.00; "Core i7 I7-4770K "; 2147.00; "Crucial Gamer"; 1253.00; "null/nothing";null/nothing
You want a LEFT OUTER JOIN.
First, clean up your code so you use ANSI joins so it's readable:
SELECT
computer_system.cs_id,
computer_system.cs_name,
motherboard.name,
motherboard.price,
cpu.name,
cpu.price,
gfx.name,
gfx.price
FROM
public.computer_system
INNER JOIN public.computer_case ON computer_system.cs_case = computer_case.case_id
INNER JOIN public.cpu ON computer_system.cs_cpu = cpu.cpu_id
INNER JOIN public.gfx ON computer_system.cs_gfx = gfx.gfx_id
INNER JOIN public.motherboard ON computer_system.cs_mb = motherboard.mb_id
INNER JOIN public.ram ON computer_system.cs_ram = ram.ram_id;
Then change the INNER JOIN on public.gfx to a LEFT OUTER JOIN:
LEFT OUTER JOIN public.gfx ON computer_system.cs_gfx = gfx.gfx_id
See PostgreSQL tutorial - joins.
I very strongly recommend reading an introductory tutorial to SQL - at least the PostgreSQL tutorial, preferably some more material as well.
It looks like it's just a bracket placement issue. Pull the null check and the graphics card id comparison into a clause by itself.
...
computer_system.cs_case = computer_case.case_id AND
(computer_system.cs_gfx IS NULL OR computer_system.cs_gfx = gfx.gfx_id)
Additionally, you ask if you should use joins. You are in fact using joins, by virtue of having multiple tables in your FROM clause and specifying the join criteria in the WHERE clause. Changing this to use the JOIN ON syntax might be a little easier to read:
FROM sometable A
JOIN someothertable B
ON A.somefield = B.somefield
JOIN somethirdtable C
ON A.somefield = C.somefield
etc
Edit:
You also likely want to make the join where you expect the null value to be a left outer join:
SELECT * FROM
first_table a
LEFT OUTER JOIN second_table b
ON a.someValue = b.someValue
If there is no match in the join, the row from the left side will still be returned.

SQL Query syntax, I want to use INNER JOIN

I'm working on a windows application project using front end "vb.net" & back end "Ms Access" I have problem in wrinting sql query
Actually there are 5 tables Transaction,items,itemtitle,itemtype & userinfo.
check the following query & with this referance if u get idea then plz change in correct query
Thanking You
SELECT
TRANSACTIONS.ACCESSIONNO AS
ACCESSIONNO,TRANSACTIONS.TYPEID,
TRANSACTIONS.CHECKOUTDATE AS CHECKOUTDATE,ITEMTITLE.ITEMTITLE,
TRANSACTIONS.CHECKEDOUTBY,
USERINFO.FULLNAME_ENG,
USERINFO.FULLNAME_MAR,
TRANSACTIONS.ACCOUNTNO,
ITEMTYPE.TYPES_MAR,
ITEMTYPE.TYPES_ENG
FROM
TRANSACTIONS,ITEMTYPE,
ITEMTITLE,
USERINFO
WHERE
TRANSACTIONS.ACCOUNTNO=USERINFO.ACCOUNTNO
AND TRANSACTIONS.ACCESSIONNO=ITEMS.ACCESSIONNO
AND ITEMS.ITEMTITLEID=ITEMTITLE.ITEMTITLEID
AND TRANSACTIONS.TYPEID=ITEMTYPE.TYPEID
AND TRANSACTIONS.STATUS='Enabled'
It looks like you left out the ITEMS table. The below joins to that table. At any rate, it demonstrates the INNER JOIN syntax. (Usually I use aliases for readability. I purposefully them out.)
SELECT TRANSACTIONS.ACCESSIONNO AS ACCESSIONNO, TRANSACTIONS.TYPEID, TRANSACTIONS.CHECKOUTDATE AS CHECKOUTDATE, ITEMTITLE.ITEMTITLE, TRANSACTIONS.CHECKEDOUTBY, USERINFO.FULLNAME_ENG, USERINFO.FULLNAME_MAR, TRANSACTIONS.ACCOUNTNO, ITEMTYPE.TYPES_MAR, ITEMTYPE.TYPES_ENG
FROM TRANSACTIONS
INNER JOIN ITEMTYPE ON (TRANSACTIONS.TYPEID = ITEMTYPE.TYPEID)
INNER JOIN ITEMTITLE ON (ITEMS.ITEMTITLEID = ITEMTITLE.ITEMTITLEID)
INNER JOIN USERINFO ON (TRANSACTIONS.ACCOUNTNO = USERINFO.ACCOUNTNO)
INNER JOIN ITEMS ON (TRANSACTIONS.ACCESSIONNO = ITEMS.ACCESSIONNO)
WHERE TRANSACTIONS.STATUS = 'Enabled'