WHERE conditions to compare columns in same table....
# orm-help
m
WHERE conditions to compare columns in same table. this is my WHERE condition for mysql query: EventCD NOT IN ('DIV' , 'DRIP') and  SEDOL = ? and PrimaryExchgCD = ExchgCD How can I do PrimaryExchgCD = ExchgCD  part (column comparision) in prisma ?
const { SEDOL } = args;
      
//  EventCD NOT IN ('DIV' , 'DRIP') and  SEDOL = ? and PrimaryExchgCD = ExchgCD"
      
const whereCondition = {
        
SEDOL,
        
EventCD: {
          
not: {
            
in: ["DIV", "DRIP"],
          
},
        
},
      
};
r
more info please. what is your schema properties? is
PrimaryExchgCD
a property? what is
ExchgCD
? a var?
m
PrimaryExchgCD, ExchgCD
are column names in mysql table.
r
try something like:
Copy code
where: {
                  AND: [
                    {EventCD: here},
                    {PrimaryExchangeCD: {equals: {ExchangeCD}}},
                    SEDOL,
                  ],
                }
m
gives error: ExchgCD is not defined. which does make sense because
ExchangeCD
is getting evaluated as a value here but I want to treat it as a column name which will be evaluated by mysql query later.
r
a) can you show your resolver now? b) can you add query logging and see what the SQL looks like?
Copy code
new PrismaClient({log: [
    'query',
    {
      emit: 'event',
      level: 'query',
    },
  ],})
m
Resolver
Copy code
Query: {
description: async (parent, args, ctx, info) => {
      console.log(parent);
      const { identifier, identifierVal } = args;
      // ListStatus <> 'D' and ActFlag <> 'D'
      const data = await ctx.prisma.eDI_SecurityMasterVMS.findFirst({
        where: {
          [identifier]: identifierVal,
          ListStatus: {
            not: "D",
          },
          Actflag: {
            not: "D",
          },
           PrimaryExchgCD: { equals: { ExchgCD } },
        },
      });
}
I dont see any log in console as the query is not successfull because of ExchgCD being undefined
Query log when I remove
PrimaryExchgCD: { equals: { ExchgCD } }
from where condition. `SELECT
vms
.
EDI_SecurityMasterVMS
.
ScexhID
,
vms
.
EDI_SecurityMasterVMS
.
SedolID
,
vms
.
EDI_SecurityMasterVMS
.
Actflag
,
vms
.
EDI_SecurityMasterVMS
.
Changed
,
vms
.
EDI_SecurityMasterVMS
.
Created
,
vms
.
EDI_SecurityMasterVMS
.
SecID
,
vms
.
EDI_SecurityMasterVMS
.
IssID
,
vms
.
EDI_SecurityMasterVMS
.
ISIN
,
vms
.
EDI_SecurityMasterVMS
.
CUSIP
,
vms
.
EDI_SecurityMasterVMS
.
IssuerName
,
vms
.
EDI_SecurityMasterVMS
.
CntryofIncorp
,
vms
.
EDI_SecurityMasterVMS
.
SIC
,
vms
.
EDI_SecurityMasterVMS
.
CIK
,
vms
.
EDI_SecurityMasterVMS
.
IndusID
,
vms
.
EDI_SecurityMasterVMS
.
SectyCD
,
vms
.
EDI_SecurityMasterVMS
.
SecurityDesc
,
vms
.
EDI_SecurityMasterVMS
.
ParValue
,
vms
.
EDI_SecurityMasterVMS
.
PVCurrency
,
vms
.
EDI_SecurityMasterVMS
.
StatusFlag
,
vms
.
EDI_SecurityMasterVMS
.
PrimaryExchgCD
,
vms
.
EDI_SecurityMasterVMS
.
SEDOL
,
vms
.
EDI_SecurityMasterVMS
.
SedolCurrency
,
vms
.
EDI_SecurityMasterVMS
.
Defunct
,
vms
.
EDI_SecurityMasterVMS
.
SedolRegCntry
,
vms
.
EDI_SecurityMasterVMS
.
StructCD
,
vms
.
EDI_SecurityMasterVMS
.
ExchgCntry
,
vms
.
EDI_SecurityMasterVMS
.
ExchgCD
,
vms
.
EDI_SecurityMasterVMS
.
MIC
,
vms
.
EDI_SecurityMasterVMS
.
Micseg
,
vms
.
EDI_SecurityMasterVMS
.
LocalCode
,
vms
.
EDI_SecurityMasterVMS
.
ListStatus
,
vms
.
EDI_SecurityMasterVMS
.
SharesOutstanding
,
vms
.
EDI_SecurityMasterVMS
.
EffectiveDate
FROM
vms
.
EDI_SecurityMasterVMS
WHERE (
vms
.
EDI_SecurityMasterVMS
.
CUSIP
= ? AND
vms
.
EDI_SecurityMasterVMS
.
ListStatus
<> ? AND
vms
.
EDI_SecurityMasterVMS
.
Actflag
<> ?) LIMIT ? OFFSET ?`