Alicia Posted November 11, 2009 Share Posted November 11, 2009 Hi, Can somebody assist me on this : What I need is to check whether UserA and UserB (which has their own unique ID in Column A) has the same transaction ID in column B under the same table. In short, I just want to compare 2 users ID which I already know (column A) and check whether have the same transaction ID in column B. Please advise and thanks. Quote Link to comment https://forums.phpfreaks.com/topic/181106-records-with-same-value-in-diff-column/ Share on other sites More sharing options...
Mchl Posted November 11, 2009 Share Posted November 11, 2009 SELECT t1.columnB= t2.columnB FROM table AS t1 CROSS JOIN table AS t2 WHERE t1.columnA=? AND t2.columnA= ? Quote Link to comment https://forums.phpfreaks.com/topic/181106-records-with-same-value-in-diff-column/#findComment-955551 Share on other sites More sharing options...
Alicia Posted November 11, 2009 Author Share Posted November 11, 2009 Hi, but both records are in the same table. So it should not use the t1 and t2 join right? t1 is table 1 and t2 is table 2 right? Quote Link to comment https://forums.phpfreaks.com/topic/181106-records-with-same-value-in-diff-column/#findComment-955597 Share on other sites More sharing options...
Mchl Posted November 11, 2009 Share Posted November 11, 2009 They are just aliases for same table. You can join table to itself. Quote Link to comment https://forums.phpfreaks.com/topic/181106-records-with-same-value-in-diff-column/#findComment-955604 Share on other sites More sharing options...
Alicia Posted November 11, 2009 Author Share Posted November 11, 2009 I tried this : SELECT * FROM f_users WHERE `user_id`='9' AND `user_id`='1595' but it returns nothing. Did I miss something. Please advise. Thank you Quote Link to comment https://forums.phpfreaks.com/topic/181106-records-with-same-value-in-diff-column/#findComment-955630 Share on other sites More sharing options...
Mchl Posted November 11, 2009 Share Posted November 11, 2009 user_id cannot be 9 AND 1595 at one time. Did you try my solution? SELECT t1.columnB = t2.columnB FROM f_users AS t1 CROSS JOIN f_users AS t2 WHERE t1.user_id= 1595 AND t2.user_id= 9 Quote Link to comment https://forums.phpfreaks.com/topic/181106-records-with-same-value-in-diff-column/#findComment-955634 Share on other sites More sharing options...
Alicia Posted November 12, 2009 Author Share Posted November 12, 2009 actually what i should replace with t1 and t2 in your query since it is under the same table? Please advise and thanks Quote Link to comment https://forums.phpfreaks.com/topic/181106-records-with-same-value-in-diff-column/#findComment-955952 Share on other sites More sharing options...
Mchl Posted November 12, 2009 Share Posted November 12, 2009 Nothing. These are just aliases for table f_users, because it is used twice in one query. All you have to do is just replcae 'columnB' with actual column name you want to compare. Quote Link to comment https://forums.phpfreaks.com/topic/181106-records-with-same-value-in-diff-column/#findComment-956003 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.