Help on simple queries

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sukatoa
    Contributor
    • Nov 2007
    • 539

    Help on simple queries

    Good day,

    I have a table named test1 and test2 which has the same column usr and pwd
    I would like to know what data in test1 that is not exist in test2

    I have no idea how to query this sample to google


    I tried this query

    select test1.usr from test1,test2 where test1.usr != test2.usr;
    (it selects all rows)

    If i will try to remove test2, it doesn't recognize test2.usr ( not on scope )

    May i ask what's the correct query for this?
    Any reply would be appreciated
  • sukatoa
    Contributor
    • Nov 2007
    • 539

    #2
    Anyways, i got it

    select usr from test1 where usr not in (select usr from test2);

    Can this query be optimized?

    Comment

    • nbiswas
      New Member
      • May 2009
      • 149

      #3
      Solution to Help on simple queries

      Even you can try this

      Code:
      select t1.usr  from test1  t1
      left join (select * from test2) t2
      on t1.usr = t2.usr
      where t2.usr is null

      Actually the above program simulates EXCEPT functionality(w hich is absent in MYSQL)

      Comment

      • sukatoa
        Contributor
        • Nov 2007
        • 539

        #4
        Thank you nbiswas for your reply, this helps

        Comment

        Working...