/    Sign up×
Community /Pin to ProfileBookmark

SQL Query.. is this possible

I have two ID’s in a table. IDa and IDb (int)

I want to find records where I have IDa and IDb but no reserve match

For example

RowID | IDa | IDb
1 | 23 | 43
2| 43 | 23

Match so nothing would return. But if row 2 wasn’t there. It would return row 1

to post a comment

2 Comments(s)

Copy linkTweet thisAlerts:
@kiwisauthorJan 04.2023 — Here's a possible bit of code - returns no rows but not sure if that's because I have none or not.

> SELECT p.* FROM peopleTable p
>
> JOIN secondTable s ON p.linkId = s.linkId
>
> WHERE p.IdA != s.IdA AND p.IdB != s.IdB
Copy linkTweet thisAlerts:
@NogDogJan 04.2023 — Assuming I understand correctly what you want (not a given), I might try:
[code=sql]
select * from peopleTable p1
where not exists(
select RowID from peopleTable p2
where p2.IDa = p1.IDb and p2.IDb = p2.IDa
);
[/code]

PS: [SQL Fiddle test](http://sqlfiddle.com/#!9/fdcd16/1/0)
×

Success!

Help @kiwis spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 4.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...