Results 1 to 4 of 4
  1. #1
    Join Date
    Jan 2011
    Posts
    2

    Unanswered: Which is the better MySQL statement?

    Hi, Iv'e been using MySQL for sometime now and I am searching for the best statements to solve my problem.

    I tested two statements below in MySQL Browser and each yield the same result. (Primary key: tbl_client.id_Client, Foreign key: tbl_order.id_Client) The first one is commonly used while the second one is the format I am more comfortable with. Does any of you knows which one is actually better? In performance issue perhaps...

    ---------------------------------------------------------

    SELECT tbl_client.Last_Name, tbl_client.First_Name
    FROM tbl_client
    INNER JOIN tbl_order
    ON tbl_client.id_Client=tbl_order.id_Client
    WHERE tbl_order.Status=1

    ---------------------------------------------------------

    SELECT C.Last_Name, C.First_Name
    FROM tbl_client AS C, tbl_order AS O
    WHERE C.id_Client=O.id_Client AND O.Status=1

    ---------------------------------------------------------

    Thanks!

  2. #2
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    first one is much, much better, if your question concerns join syntax

    second one is better, albeit not by much, if your question concerns table aliases

    bofadem fail the table name criterion of clarity (i.e. if you're gonna call the tables "tbl_something" then why don't you call the columns "col_something" as well)

    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  3. #3
    Join Date
    Jan 2011
    Posts
    2
    Quote Originally Posted by r937 View Post
    first one is much, much better, if your question concerns join syntax

    second one is better, albeit not by much, if your question concerns table aliases

    bofadem fail the table name criterion of clarity (i.e. if you're gonna call the tables "tbl_something" then why don't you call the columns "col_something" as well)

    Yeah, my table naming is a fail... but then I am the only ones who read them anyway and its pretty clear from here.

    Back to my original concern... How about performance? Efficiency between two codes? You know anything about it?

  4. #4
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    Quote Originally Posted by Rai_Yan View Post
    Efficiency between two codes? You know anything about it?
    some

    for all your tents and porpoises, they perform the same

    this can ~not~ be said, however, if you want a left outer join instead of an inner join

    then they are uncomparable
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

Posting Permissions

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