I have the following 2 SQL syntax that I’m looking to combine into 1 SQL syntax
SELECT sentFrom
FROM tableName
WHERE id = :varid
AND sentFrom != :vartext
SELECT sentTo
FROM tableName
WHERE id = :varid
AND sentTo != :vartext
I guess I should give an example:
MYSQL TABLE
-----------------------------------
sentFrom sentTo
1 2
1 3
2 1
2 3
query
select sentFrom where sentFrom != 1 and select sentTo where sentTo != 1
Returns:
sentTo 2 but not sentFrom 1
sentTo 3 but not sentFrom 1
sentFrom 2 but not sentTo 1
sentFrom 2 and sentTo 3
I think this should help.
If you think,
IDis not common in the rows selected in each query then remove the join conditionON a.id = b.id. In that case it will return you theCartesian productof records of query one to query 2.