简体   繁体   中英

PHP PDO - Exclude a particular row from a query

I am working with PDO to connect to my database. I would like to perform a query and exclude a particular row from my query only. I'm not sure how to do it.

From the suggestions I got from another question, I posted this is my current solution right now but it doesn't work

$queryProfileCode = $dbh->prepare("SELECT profile_code FROM tableBusinessProfiles WHERE profile_code = ? AND NOT EXISTS(SELECT * FROM tableBusinessProfiles WHERE profile_code = $businessProfileIDUrl)");
$queryProfileCode->bindValue(1,$profileCode);
$queryProfileCode->execute();
$resultTableProfileCode = $queryProfileCode->fetchAll();

I couldn't find how to exclude a particular record from my query.

your query should be

SELECT 
profile_code 
FROM tableBusinessProfiles 
WHERE 
profile_code != $businessProfileIDUrl

or

SELECT 
profile_code 
FROM tableBusinessProfiles 
WHERE 
id NOT IN ($businessProfileIDUrl);

The MySQL "not equal to" operaters are != and <>**

I'm not sure what you try to achieve? The problem is the query?

Do you want to get ALL profile_codes FROM tableBusinessProfiles WHERE profile_code DOES NOT EQUAL TO $businessProfileIDUrl ?

The query could then be:

SELECT profile_code FROM tableBusinessProfiles WHERE profile_code != $businessProfileIDUrl

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM