Jump to content

Recommended Posts

I've got 2 tables

content (id-int, uid-int, catid-int, contenttext-text)

usedblocks (id-int, userid-int, contentid-int)

 

I want to select all the blocks where category id = X that don't exist on usedblocks where userid=X

Here is what I got so far...

select contenttext from content left join usedblocks on content.id=usedblocks.contentid where usedblocks.userid CAN'T FIGURE THIS OUT AND content.categoryid = 1 order by rand();

 

I want to select where usedblocks.userid != 1, but that doesn't work...

 

Can anyone help me? Thanks!

I've tried both, Here is the exact query that failed.

 

I'm doing something wrong, because when I do

select contenttext from content left join usedblocks on content.id=usedblocks.contentid where usedblocks.userid <> 1 AND content.categoryid = 1 order by rand() limit 1

 

I don't get what I want (I get nothing).

If I have

category table --  (id=1, name=category1)

content table -- (id=1, categoryid=1, text=AAA)  AND  (id=2, categoryid=1, text=BBB) AND (id=3, categoryid=1, text=CCC)

usedblocks table -- (id=1, userid=1, contentid=2)

 

If I run the query on category 1 for userid 1, I should get the content AAA and CCC (BBB isn't included, since it's in the usedblocks table for user 1)

You have:

 

where usedblocks.userid  1

 

And in your sample data you have:

 

usedblocks table -- (id=1, userid=1, contentid=2)

 

which won't return anything cause you don't have a userid from this table where it's not 1...

 

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.