How do you conduct an outer join in typeorm? - typeorm

I am using typeorm in a project and want to conduct a left outer join. After going through their docs there is no mention of this at all and i am not convinced that left join will do what i need it to do. Is there a way to conduct an outer join in typeorm?
Just to share, this is the query i am trying to convert to typeorm:
SELECT bsm."bId"
FROM (
SELECT bs."id" "statusId", bs.label label, bs_mapping."bId" "bId"
FROM bs_mapping
LEFT JOIN bs
ON bs.id = bs_mapping."binStatusId"
) bsm
LEFT OUTER JOIN tt_bs
ON tt_bs."statusId" = bsm."statusId"
WHERE ((bsm.label = 'inactive' OR bsm.label = 'block') AND
tt_bs."ttId" IS NULL')
GROUP by bsm."bId"

Related

SQL Join issue with 3 tables and a subquery

Tables Involved:
account, user, service, accesshist
I want to include all records in the account table, and only the data from the other tables when it exists.
Count from account: 5064
rows returned from query below: 4915
select u.last_name, u.first_name, a.username, ll.mxlogin, si.servicename, a.islockedout
from account a
join service si on a.serviceid = si.serviceid
left outer join user u on u.loginid = a.username
left outer join(select max(loginattemptdate) as MxLogin, usernameattempted from accesshist where isloginsuccessful = 1
group by usernameattempted) ll
on a.username = ll.usernameattempted
where a.isenabled = 1
order by ll.mxlogin, u.last_name
I've narrowed it down that the subquery join is the part causing the number of rows to be reduced, but I am unsure how to correct it. Any insight is greatly appreciated!
Have you tried changing the first join to a left outer join?
select u.last_name, u.first_name, a.username, ll.mxlogin, si.servicename, a.islockedout
from account a
left outer join service si on a.serviceid = si.serviceid

Solr5.4 indexing using DataImportHandler(joins)

I am using Solr 5.4. Working on indexing entities using Data Import Handler which are having inner joins and left joins as below.
Does solr5.4 supports inner joins and left joins?
I am having a query which has relationship between 7 tables. I am doing inner joins for few and left joins for few tables.
below is my query declared in data-config.xml file.
SELECT rel.*,
PRODUCT_SRC_SYS.PRODUCT_SRC_NME AS sourceName
FROM (SELECT REF.*,
PRODUCT_RLSP.OBJ_ID AS relObjId
FROM (SELECT prdct.*,
PRODUCT_CATEGORY.OBJ_ID AS refObjId
PRODUCT_CATEGORY_MAPG.category_mapng_Name
AS refCategoryMapngName,
PRODUCT_CATEGORY_LIFE_CYL.LIFE_CYL_STAT_TYP
AS refStatus
FROM (SELECT PRODUCT.RGSTRY_ID
AS id
PRODUCT.OBJ_ID
AS obj_id,
PRODUCT.PRODUCT_NAME
As product_name,
PRODUCT_STAT.PRODUCT_STAT_TYP
AS status
FROM PRODUCT
LEFT JOIN PRODUCT_STAT
ON PRODUCT.OBJ_ID =
PRODUCT_STAT.OBJ_ID)
prdct
LEFT JOIN PRODUCT_CATEGORY
ON prdct.product_name =
PRODUCT_CATEGORY.category_name
INNER JOIN PRODUCT_CATEGORY_MAPG
ON PRODUCT_CATEGORY.OBJ_ID =
PRODUCT_CATEGORY_MAPG.OBJ_ID
INNER JOIN PRODUCT_CATEGORY_LIFE_CYL
ON PRODUCT_CATEGORY.OBJ_ID =
PRODUCT_CATEGORY_LIFE_CYL.OBJ_ID)
REF
LEFT JOIN PRODUCT_RLSP
ON REF.obj_id =
PRODUCT_RLSP.OBJ_ID) rel
LEFT JOIN PRODUCT_SRC_SYS
ON rel.obj_id = PRODUCT_SRC_SYS.OBJ_ID
Any help is highly appreciated!!

How to remove duplicates after join in SQL

I am very new to SQL - be kind! I am trying to remove duplicates from this join. What is my next step?! I know to use select distinct but not sure where...
SELECT
ac.[dc_id]
,center_name
,ecec
,inspec_date
,facility_type
,sitetype
,new_sitetype
FROM
usrbesp.wrk_city_active_sites ac
INNER JOIN
usrbesp.t_gdc_activity a ON ac.dc_id = a.dc_id
ORDER BY
dc_id
Use can use DISTINCT but keep in mind that it is distinct against all columns in the SELECT
SELECT DISTINCT
ac.[dc_id]
,center_name
,ecec
,inspec_date
,facility_type
,sitetype
,new_sitetype
FROM usrbesp.wrk_city_active_sites ac
inner JOIN usrbesp.t_gdc_activity a
ON ac.dc_id = a.dc_id
order by dc_id

Workaround for non equal hive queries

I try to rewrite follow query on hive
select
TFCT_CHARGE.SUBS_KEY,
TFCT_CHARGE.PRODUCT_KEY,
TFCT_CHARGE.CHARGE_NVAL,
TFCT_CHARGE.B_SUBS_KEY,
TFCT_CHARGE.DELETE_DT,
HFCT_SUBS_SEGMENT.SEGMENT_KEY,
TFCT_CHARGE.EVENT_DT,
TFCT_CHARGE.DWH_SRC_TABLE_KEY
from
TFCT_CHARGE LEFT OUTER JOIN HFCT_SUBS_SEGMENT
ON (
TFCT_CHARGE.B_SUBS_KEY = HFCT_SUBS_SEGMENT.SUBS_KEY and
TFCT_CHARGE.EVENT_DT >= HFCT_SUBS_SEGMENT.EFF_DT and
TFCT_CHARGE.EVENT_DT < HFCT_SUBS_SEGMENT.EXP_DT and
HFCT_SUBS_SEGMENT.SEGMENT_TYPE_KEY = 1)
But there are non-equal query.
Could anybody hint me some workaround?
Tnx!
To emulate a non-equi left outer join:
Create a copy of the left table with added serial row numbers
Do an inner join:
Left join by serial:
See my answer here for the code: Hive: work around for non equi left join
It's quite easy)))
select
TFCT_CHARGE.SUBS_KEY,
TFCT_CHARGE.PRODUCT_KEY,
TFCT_CHARGE.CHARGE_NVAL,
TFCT_CHARGE.B_SUBS_KEY,
TFCT_CHARGE.DELETE_DT,
HFCT_SUBS_SEGMENT.SEGMENT_KEY,
TFCT_CHARGE.EVENT_DT,
TFCT_CHARGE.DWH_SRC_TABLE_KEY
from
TFCT_CHARGE INNER JOIN HFCT_SUBS_SEGMENT
ON (
TFCT_CHARGE.B_SUBS_KEY = HFCT_SUBS_SEGMENT.SUBS_KEY
HFCT_SUBS_SEGMENT.SEGMENT_TYPE_KEY = 1)
where
TFCT_CHARGE.EVENT_DT >= HFCT_SUBS_SEGMENT.EFF_DT and
TFCT_CHARGE.EVENT_DT < HFCT_SUBS_SEGMENT.EXP_DT and

Number of joins in select query

I have a business table and in that we have 50 foreign key columns which refers other master data tables.
to fetch all the data my query has to join all the 50 reference tables like
select ct.id , ct.name , ct.description , st.value , pr.value , sv.value , ....
from
core_table ct
left outer join domain_value st on ct.status_fk = st.id
left outer join domain_value pr on ct.priority_fk = pr.id
left outer join domain_value svon ct.severity_fk = sv.id
.......
.......
so like this i need to make 50 left outer joins.
is this right to do 50 left outer joins like this or do we have any other optimized way to achieve this ?
Is too many Left Joins a code smell?
It's a perfectly legitimate solution for some designs.

Resources