Jump to content

Mind Boggling (need help)


skina

Recommended Posts

Hi, im having a problem with some SQL code, it looks really simple and i really can\'t understand why it\'s not giving the desired output, any help would be greatly appreciated:

 

This is the SQL statement i\'m trying to run:

 


SELECT t2.* FROM t1, t2 WHERE t1.rid <> t2.rid;

 

table1:

 

ID rid

31 1

32 2

 

table2:

 

ID rid

9 1

10 2

11 3

12 4

13 5

 

I was expecting the output to be:

 

11 3

12 4

13 5

 

But instead got:

 

ID rid

10 2

10 2

11 3

11 3

11 3

12 4

12 4

12 4

9 1

9 1

13 5

13 5

13 5

 

 

This seemed pretty crazy to me, all i wanted was for the query to retrieve only the records which didnt have matching rid\'s. This was all done on phpmyadmin as after having problems with the code i thought it would be easier to debug it using phpmyadmin. If anyone can tell me why its showing all the results multiple times and also a way i can recieve the data i want it to will be greatly appreciated.

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.