Discover Habbo's history
Treat yourself with a Secret Santa gift.... of a random Wiki page for you to start exploring Habbo's history!
Happy holidays!
Celebrate with us at Habbox on the hotel, on our Forum and right here!
Join Habbox!
One of us! One of us! Click here to see the roles you could take as part of the Habbox community!


Results 1 to 5 of 5
  1. #1
    Join Date
    Sep 2006
    Location
    Evanston, Illinois.
    Posts
    2,361
    Tokens
    0

    Latest Awards:

    Default [SQL] Joins, Unions and Intersects

    OK. Somebody at work tried to explain it to me like it's a venn diagram of SQL objects.

    But I just didn't get it. Could somebody try to explain it in a simpler form, also could you give me an example where it would be needed. I've googled around but I've only got very confusing results, partly to it being an advanced topic coined by Tizag.

    Uh, I'm supposed to have left... oh well.
    How could this hapen to meeeeeeeeeeeeeee?lol.

  2. #2
    Join Date
    Oct 2006
    Location
    Peterborough, UK
    Posts
    3,855
    Tokens
    216

    Latest Awards:

    Default

    Joins / left joins / right joins / inner joins are just joining stuff onto stuff

    http://www.w3schools.com/Sql/sql_join.asp that is the easiest to learn.

    Union is simple, it's just retrieving data from n select queries instead of 1.

    SELECT `blah` FROM `table1` UNION SELECT `blah` FROM `table2`

    if there was results in both table1 and table2 for field blah it would return from both, you can extend this to however many you need. You can use order by and where, but you can't use table.row (e.g ORDER BY `table2.blah`) you have to use `blah`

    Intersect is the same as union but is used in mssql as far as I know.

  3. #3
    Join Date
    Sep 2006
    Location
    Evanston, Illinois.
    Posts
    2,361
    Tokens
    0

    Latest Awards:

    Default

    Quote Originally Posted by Jewish Bear View Post
    Joins / left joins / right joins / inner joins are just joining stuff onto stuff

    http://www.w3schools.com/Sql/sql_join.asp that is the easiest to learn.

    Union is simple, it's just retrieving data from n select queries instead of 1.

    SELECT `blah` FROM `table1` UNION SELECT `blah` FROM `table2`

    if there was results in both table1 and table2 for field blah it would return from both, you can extend this to however many you need. You can use order by and where, but you can't use table.row (e.g ORDER BY `table2.blah`) you have to use `blah`

    Intersect is the same as union but is used in mssql as far as I know.
    I'll read up on Joins.

    Unions seems easy enough.

    I think your wrong on Intersects, I thought it was something like a union, but selecting distinct values that correlate through foreign keys, then again this is why I am asking.
    How could this hapen to meeeeeeeeeeeeeee?lol.

  4. #4
    Join Date
    Oct 2006
    Location
    Peterborough, UK
    Posts
    3,855
    Tokens
    216

    Latest Awards:

    Default

    Quote Originally Posted by Hypertext View Post
    I'll read up on Joins.

    Unions seems easy enough.

    I think your wrong on Intersects, I thought it was something like a union, but selecting distinct values that correlate through foreign keys, then again this is why I am asking.
    Yeah my head is pretty messed up at the minute, union executes the queries separately and just bungs everything into 1 result. intersect does the same but only returns the rows that are the same in each table.

  5. #5
    Join Date
    Sep 2006
    Location
    Evanston, Illinois.
    Posts
    2,361
    Tokens
    0

    Latest Awards:

    Default

    Oh OK. Thanks, I think I have a better understanding now.
    How could this hapen to meeeeeeeeeeeeeee?lol.

Posting Permissions

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