Combining AND with OR in Database Query

Hello! :+1:

How can I combine AND with OR queries in the Wappler database query builder?
I checked the Docs but it seems like that was an older version that was different.

I’d like to say, find all the database records where:
(A1 = A2) OR (A1 = null AND A2 = null)

Want more details?
I’m looking for duplicate addresses in my database. I want to be able to say:
Select PropertyID From CustomerAddresses WHERE…
City1 = City2
Zip1 = Zip2
Street1 = Street2
PrimaryNumber1 = PrimaryNumber2
SecondNumber1 = SecondNumber2
etc.

But, sometimes values will be null. Particularly the Second Number in the address. So, if I do
SecondNumber1 = SecondNumber2
it will return false instead of true when they are both null.
So I need to be able to say:

WHERE
(SecondNumber1 = SecondNumber2) OR (SecondNumber1 = null AND SecondNumber2 = null).

But I’m not sure how to accomplish that in the query builder.
THANKS!
Jeff

You can use the Add Group (folder with plus icon) to create groups and combine them however you need.

Random example:

Screen Shot 2020-10-15 at 7.54.58 AM

1 Like

I was trying the group thing… never added two at a time so the “OR” never showed up. LOL

THANK YOU!

Just to be clear, in your example there, it’s saying to select where:
Gender = GET.gender
AND
where first name = get.name or last name = get.name

Right?
Just double checking that the indentation doesn’t make it a subgroup of gender.

THANKS!

Yes.

Gender = GET.gender AND ( first name = get.name OR last name = get.name)

but only when the corresponding get variables are provided.

I’ll add that the grouping is one of the nicest interfaces within the UI…very easy to work with.

1 Like

To follow up, I have a different problem.
I’m searching the current database values (Address1) and comparing them with a result from a database query (Address2).

But, how in Wappler’s Database Query Builder do I say:
Search for (this stuff) and…
(Address1 = Address 2) OR (Address 1=null AND Address2=null).

Because, as you can see Address2 isn’t one of the items I can select on the left side.
These values are from the same database.

Basically, they entered a new address.
Then I did a query to find the new address and I’m selecting ALL from the database that are the same.