SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Zealot
    Join Date
    May 2005
    Posts
    172
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    MySQL Query help

    Hi

    I have two tables - cats and manufacturers. Both have primary 'id' fields. I need to merge them and so want to find out how many have the same id.

    I've tried this:
    SELECT 'cats.id', 'cats.name'
    FROM `cats`
    INNER JOIN `manufacturers`
    ON 'cats.id'='manufacturers.id'
    But that returns an emtry set and I know that cannot be correct.

    Any ideas. Thanks

  2. #2
    SitePoint Enthusiast rajeev13's Avatar
    Join Date
    Nov 2012
    Location
    New Delhi,India
    Posts
    35
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by rooftop View Post
    Hi

    I have two tables - cats and manufacturers. Both have primary 'id' fields. I need to merge them and so want to find out how many have the same id.

    I've tried this:

    But that returns an emtry set and I know that cannot be correct.

    Any ideas. Thanks
    According to your query there must be a result set from the both-table( join ).
    check manually is there any id is same or not.
    Your query seems no error.

  3. #3
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,215
    Mentioned
    58 Post(s)
    Tagged
    3 Thread(s)
    Quote Originally Posted by rooftop View Post
    But that returns an emtry set and I know that cannot be correct.
    look carefully at your ON clause

    you are comparing two strings, and they are not equal, so you get an empty result set

    now ask yourself why you used strings there

    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  4. #4
    SitePoint Enthusiast rajeev13's Avatar
    Join Date
    Nov 2012
    Location
    New Delhi,India
    Posts
    35
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i forgot to keep eyes on single quotes.

  5. #5
    Keeper of the SFL StarLion's Avatar
    Join Date
    Feb 2006
    Location
    Atlanta, GA, USA
    Posts
    3,748
    Mentioned
    69 Post(s)
    Tagged
    0 Thread(s)
    Off Topic:

    Probably a reason they put ' and ` so far away from each other on the keyboard
    Never grow up. The instant you do, you lose all ability to imagine great things, for fear of reality crashing in.


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
  •