SitePoint Sponsor

User Tag List

Results 1 to 5 of 5

Thread: Sql Help

Hybrid View

  1. #1
    Free me php klassicd's Avatar
    Join Date
    Sep 2001
    Location
    San Diego
    Posts
    509
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Sql Help

    I know its the wrong board but i need some quick help.

    Anyone know how to select userid from table2 where userid doesnt exsist in table1?

    Anyone know how to select from table2 where userid is in more than one row.


    Im trying to find where these extra userid's came from.

  2. #2
    Your Lord and Master, Foamy gold trophy Hierophant's Avatar
    Join Date
    Aug 1999
    Location
    Lancaster, Ca. USA
    Posts
    12,305
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    I am assuming you are using MySQL. You would have to pull both tables into an Array and step through them in the language of your choice.

    If you are not using MySQL you can use a subselect like:

    SELECT userid FROM table2 WHERE userid NOT IN (SELECT userid FROM table1)
    Wayne Luke
    ------------


  3. #3
    SitePoint Wizard
    Join Date
    Jul 1999
    Location
    Chicago
    Posts
    2,629
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Likewise for the second one. If you are not using MySQL:

    Code:
    SELECT userid FROM table1 WHERE userid IN (SELECT userid FROM table1);

  4. #4
    SitePoint Guru
    Join Date
    Jan 2001
    Location
    Alkmaar, Netherlands
    Posts
    710
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Anyone know how to select userid from table2 where userid doesnt exsist in table1?

    select * from table2
    LEFT JOIN table1 ON table2.userid = table1.userid WHERE table1.userid is NULL
    ---------------------------

    Anyone know how to select from table2 where userid is in more than one row.

    SELECT userid, count(userid) as useridcount FROM table1 GROUP BY userid HAVING useridcount > 1
    ---------------------------------

  5. #5
    Free me php klassicd's Avatar
    Join Date
    Sep 2001
    Location
    San Diego
    Posts
    509
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Thanks

    Thanks sylow. Just what i needed.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •