SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    Free Geek computerages's Avatar
    Join Date
    Oct 2004
    Location
    /dev/null
    Posts
    1,071
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Red face Performing Joins

    Hello Everyone!

    I am plain newbie to mysql and this is the first time I am using JOINS in my query. What I am trying to do is to select some fields from news table which connects to authors table by an "authorid" field. I want to replace that"authorid" field with "name" field which is in the authors table. I have heard from a friend of mine that it is possible to accomplis by using mysql JOIN function but I have no idea how should I go about that....

    Any help would be greatly appreciated!

  2. #2
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,341
    Mentioned
    63 Post(s)
    Tagged
    3 Thread(s)
    you need a tutorial on joins

    start with this one -- Understanding SQL Joins
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  3. #3
    Free Geek computerages's Avatar
    Join Date
    Oct 2004
    Location
    /dev/null
    Posts
    1,071
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Red face

    Quote Originally Posted by r937
    you need a tutorial on joins

    start with this one -- Understanding SQL Joins
    Thanks for the link. But whenever I execute the following query nothing outputs except an error message saying that there is an error in query's syntax. Here is the query:

    Code:
      "SELECT ".
       		   "authors.name, ".
       		   "articles.id, ".
       		   "articles.name, ".
       		   "articles.usrfrndname, ".
       		   "articles.addedon, ".
       		   "articles.intro, ".
       		   "FROM authors ".
       		   "LEFT JOIN articles ".
       		   "ON authors.id=articles.authorid ".
       		   "ORDER BY articles.id DESC ".
       		   "LIMIT 4",
    Could you please check it and tell me what is wrong with it... Thanks.

  4. #4
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,341
    Mentioned
    63 Post(s)
    Tagged
    3 Thread(s)
    piece o' cake

    you have a dangling comma in front of the FROM keyword



    note: this would have been a lot easier for you to spot if you had used the "leading comma" programming convention for items in a list --
    Code:
    SELECT authors.name
         , articles.id
         , articles.name
         , articles.usrfrndname
         , articles.addedon
         , articles.intro
         , 
      FROM authors
    LEFT 
      JOIN articles
        ON authors.id=articles.authorid
    ORDER 
        BY articles.id DESC LIMIT 4
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  5. #5
    Free Geek computerages's Avatar
    Join Date
    Oct 2004
    Location
    /dev/null
    Posts
    1,071
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks.

    (rep ++)


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
  •