/    Sign up×
Community /Pin to ProfileBookmark

Not sure whether to put this in PHP or MySQL forums.

I want to select an entry from a table where it’s value is NOT LIKE any values in the result of a previous query.

How do I go about this?

For example, I run a query to find the ID’s of all items that are in a history table. I then want to run a query that finds a single entry from another table, WHERE the ID is different from all of the results in the history table.

Thanks, TK

to post a comment
PHP

4 Comments(s)

Copy linkTweet thisAlerts:
@ss1289Mar 23.2008 — Get the array of your first results then use implode()
[code=php]$comma_separated = implode(",", $array);[/code]
This will put them into a string called $comma_seperated and each entry will be separated by a column.

Then run a query like.
[code=php]SELECT ... FROM ... WHERE Id NOT IN ($comma_separated);[/code]

That's an idea.
Copy linkTweet thisAlerts:
@AnotherMuggleauthorMar 23.2008 — Nice one.

Much appreciated ?
Copy linkTweet thisAlerts:
@padreMar 24.2008 — you can do it in one sql query

eg, select all users that have never left a comment

SELECT * FROM user WHERE userId NOT IN (SELECT userId FROM comment)
Copy linkTweet thisAlerts:
@AnotherMuggleauthorMar 24.2008 — you can do it in one sql query

eg, select all users that have never left a comment

SELECT * FROM user WHERE userId NOT IN (SELECT userId FROM comment)[/QUOTE]

Looks like this would also do the job ?
×

Success!

Help @AnotherMuggle 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 6.18,
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: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

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