Results 1 to 5 of 5

Thread: Very simple request in MYSQL but getting no output

  1. #1
    Join Date
    Nov 2008
    Posts
    996

    Very simple request in MYSQL but getting no output

    I have a very simple query to do and yet I can not, I am fine based on a book. I have two tables: "pages" and "users". In the Pages table, the fields author_id corresponds to id in the users table of the author of the page. "name" is the name of the table field that contains the users name.
    Here's where I am:

    Code:
      SELECT pages.author_id, users.name 
      FROM pages, users 
      WHERE pages.id = { $this->id } AND users.id = pages.author_id
    No error from mysql but no return when the ID that I provided is correct. It is surely very simple but I do not understand the whole problem

  2. #2
    Join Date
    May 2008
    Posts
    271

    Re: Very simple request in MYSQL but getting no output

    Use a JOIN instead of a WHERE condition to join your two tables.

    There you met WHERE MyTable.id = my_other_table.fk_id
    Use rather FROM MyTable INNER JOIN my_other_table ON id = fk_id

  3. #3
    Join Date
    May 2008
    Posts
    945

    Re: Very simple request in MYSQL but getting no output

    author_id is zero so it can not work

  4. #4
    Join Date
    May 2008
    Posts
    685

    Re: Very simple request in MYSQL but getting no output

    Quote Originally Posted by XSI View Post
    Use a JOIN instead of a WHERE condition to join your two tables.

    There you met WHERE MyTable.id = my_other_table.fk_id
    Use rather FROM MyTable INNER JOIN my_other_table ON id = fk_id
    Why? Does it improves performance, or is it another reason?

  5. #5
    Join Date
    May 2008
    Posts
    271

    Re: Very simple request in MYSQL but getting no output

    Yes it improves performance as well as readability.

Similar Threads

  1. Replies: 4
    Last Post: 11-01-2014, 10:14 AM
  2. Replies: 3
    Last Post: 07-11-2009, 09:36 PM
  3. "Simple" many to many relationship - MySQL
    By Soft Pack in forum Software Development
    Replies: 6
    Last Post: 07-04-2009, 10:36 AM
  4. Simple MYSQL Normalization question - input requested
    By ByteCoder in forum Software Development
    Replies: 1
    Last Post: 19-02-2009, 12:14 PM
  5. Replies: 3
    Last Post: 10-05-2007, 11:12 PM

Tags for this Thread

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
  •  
Page generated in 1,715,561,554.31798 seconds with 17 queries