[SOLVED] WHERE NOT EXISTS(subquery)

Discuss about Group-Office development here

Moderator: Developers

jamesarthur
Posts: 55
Joined: Fri Nov 08, 2013 9:15 am

[SOLVED] WHERE NOT EXISTS(subquery)

Postby jamesarthur » Mon Feb 10, 2014 2:47 pm

Is there a way in groupoffice to do a WHERE NOT EXISTS subquerry?
Last edited by jamesarthur on Wed Feb 12, 2014 10:38 am, edited 1 time in total.
mschering
Site Admin
Site Admin
Posts: 8281
Joined: Tue Apr 20, 2004 1:06 pm
Location: The Netherlands - Den Bosch
Contact:

Re: WHERE NOT EXISTS(subquery)

Postby mschering » Mon Feb 10, 2014 3:56 pm

Yes, but you have to use addRawCondition();
Best regards,

Merijn Schering
Intermesh
jamesarthur
Posts: 55
Joined: Fri Nov 08, 2013 9:15 am

Re: WHERE NOT EXISTS(subquery)

Postby jamesarthur » Wed Feb 12, 2014 10:38 am

Hi

Yes this worked. I did

Code: Select all

addRawCondition('NOT', '('.$subquery.')', 'EXISTS')
 
mschering
Site Admin
Site Admin
Posts: 8281
Joined: Tue Apr 20, 2004 1:06 pm
Location: The Netherlands - Den Bosch
Contact:

Re: [SOLVED] WHERE NOT EXISTS(subquery)

Postby mschering » Wed Feb 12, 2014 12:26 pm

Yes, make sure $subquery is not vulnarable to injections because when using addRawCondition there are no security checks.
Best regards,

Merijn Schering
Intermesh
jamesarthur
Posts: 55
Joined: Fri Nov 08, 2013 9:15 am

Re: [SOLVED] WHERE NOT EXISTS(subquery)

Postby jamesarthur » Thu Feb 13, 2014 1:31 pm

Good point! - My subquery doesn't have any data fields - it's purely of the form

Code: Select all

SELECT * FROM `table2`
WHERE `table1`.`id` = `table2`.`id`
but if there was data needing escaping, I would need to use addBindParam..
mschering
Site Admin
Site Admin
Posts: 8281
Joined: Tue Apr 20, 2004 1:06 pm
Location: The Netherlands - Den Bosch
Contact:

Re: [SOLVED] WHERE NOT EXISTS(subquery)

Postby mschering » Thu Feb 13, 2014 3:14 pm

Spot on, addBindParam is the safest.
Best regards,

Merijn Schering
Intermesh

Who is online

Users browsing this forum: No registered users and 2 guests