NameSilo

[MySQL] Return rows where fields not equal to value

Namecheap AuctionsNamecheap Auctions
Namecheap AuctionsNamecheap Auctions
SpaceshipSpaceship
Watch

Just_Dave

Established Member
Impact
2
Hi. I'm totally at a loss. I've spent practically all day trying to make this work, but I can't. I'd really appreciate any help.

I have the following sql statement:

Code:
SELECT DISTINCT tbl_1.a
FROM tbl_1 JOIN tbl_2 ON tbl_2.a=tbl_1.a JOIN tbl_3 ON tbl_3.a=tbl_1.a
WHERE tbl_3.b IN ([a load of values]) AND tbl_2.c NOT IN ('thisValue')
GROUP BY tbl_2.a

tbl_1 - tbl_2 is a one-many relationship.

tbl_1 - tbl_3 is a one-many relationship.

I want the query to return all rows from tbl_1 where none of tbl_2.c equals 'thisValue'. But it doesn't.

EDIT:

Basically, if there are 2 or more tbl_2 rows connected, then even if one of the tbl_2.c fields equals 'thisValue', it returns the tbl_1 row it is connected to because there is a tbl_2.c field that doesn't equal 'thisValue'.

end of edit

I've also done tbl_2.c<>'thisValue' instead of tbl_2.c NOT IN ('thisValue'): same results.

Can anyone help please. I hope I've provided enough info.

Thanks in advance.
 
Last edited:
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
GoDaddyGoDaddy
EIDITED


Ok. I've found a way round, but instead of one query, i've got two.


If anyone has a solution still for just one query, great. But i'm no longer desperate.

Thanks.
 
Last edited:
0
•••
can you provide example content and what you want to retrieve just to make sure I understand exactly what you are after. I find it easier looking at examples than reading the description.

It should be easy enough to do.
 
0
•••
attachment.php


tbl_3 isn't important for this.

I want to return all the rows in tbl_1 where there isn't a connected row in tbl_2 with field c equaling 'thisValue'. But if there are two or more tbl_2 rows connected to the tbl_1 row, then because not all the tbl_2.c fields equal 'thisValue' it will still return that tbl_1 row. I don't want that. What I want is for the tbl_1 row to be discarded from the results as soon as there's tbl_2.c field that equals 'thisValue'.


EDIT:
I just had another look at the image I made. There should be a few tbl_2.a fields that equal the same value. Sorry about that. It is new years.
end of edit

Thanks in advance for help, and happy New Year!
 

Attachments

  • 00000001.gif
    00000001.gif
    2 KB · Views: 80
Last edited:
0
•••
DomainEasy: white label portfolios are live. Enable yours.

We're social

Escrow.com
Spaceship
Escrowly
CryptoExchange.com
Domain Recover

NamePros updates

Parking: find your domains by pasting a list
You can now paste a list of domain names into the search box at the top of the Parking menu. Put one name on each line. Your domain list...
AIVikings
Catchy
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back