Jump to content

[SOLVED] Displaying rows of tables where ID does not exist in other table.


Recommended Posts

In my Dbase we have 2 tables - Predictions and Fixtures. They are linked by colum 'id'.

 

I am able to show all fixtures where the user has predicted but I want to show all fixtures where the user hasn't. To show where they all HAVE (and this works)...

 

SELECT fixtures.dateplayed, fixtures.opponent, fixtures.resultus, fixtures.resultthem, predictions.resultmfc, predictions.resultother, predictions.score FROM predictions Right Join fixtures ON fixtures.id = predictions.id AND predictions.username = '$session->username' ORDER BY fixtures.dateplayed DESC

 

So I tried...

 

SELECT fixtures.dateplayed, fixtures.opponent FROM predictions Right Join fixtures ON fixtures.id != predictions.id AND predictions.username = '$session->username' ORDER BY fixtures.dateplayed DESC
and that didn't work. It just showed the prdedictions over about 10 times.

 

I have tried IS NULL but if a prediction has not been made for a fixture then a row doesn't exist at all in predictions table. Is there a 'does not exist at all' SQL command. If you need mroe info let me know.

 

Thanks

Thank you for your help. I sort of see what you are getting at, however SQL errors...

 

MySQL said: 

 

#1109 - Unknown table 'predictions' in where clause

 

There is definitely a predictions table? It doesn't like the bit in brackets though.

I am able to show all fixtures where the user has predicted but I want to show all fixtures where the user hasn't. To show where they all HAVE (and this works)...

 

SELECT fixtures.dateplayed, fixtures.opponent, fixtures.resultus, fixtures.resultthem, predictions.resultmfc, predictions.resultother, predictions.score FROM predictions Right Join fixtures ON fixtures.id = predictions.id AND predictions.username = '$session->username' ORDER BY fixtures.dateplayed DESC

 

You said you had that working already? You JOIN here looks good.

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.