Jump to content

[SOLVED] SELECT from a table if a record doesn't exist in another?


Strahan

Recommended Posts

I have a table that I want to query for records that are not marked in another table.  For example, this is the source table "chars":

id [int, index]

chartxt [text]

 

Then there is the other table: "charused":

uid [int, index]

cid [int]

user [int]

 

A logged in user gets a numeric ID, say 123.  I want to get a random record from the database, but one that hasn't been used yet.  When the client uses a "character", it enters a record with the char ID into the charused table so I can keep track of what has been used and what hasn't.

 

I was thinking select chartxt from chars right outer join charused on chars.id = charused.cid where charused.user is null order by rand() limit 1

 

So it would pull a record but only if the user is null in charused, meaning no record was found there.  However, that doesn't seem to work.  Any ideas?

 

Thanks!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.