user2333968
user2333968

Reputation: 135

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.

Upvotes: 0

Views: 568

Answers (2)

Prashant Tapase
Prashant Tapase

Reputation: 2147

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 <>**

Upvotes: 1

PHPJScoder
PHPJScoder

Reputation: 11

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

Upvotes: 0

Related Questions