SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Evangelist Tapan's Avatar
    Join Date
    May 2005
    Location
    India
    Posts
    557
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    not sure how to use inner join (was "MySQL Query Help Please...")

    Hello,

    Basically i have 2 tables users and listings. In users table there is user's info like username / password etc. and in listings table there are listings of a user..which can be more than 1.

    Currently I was just getting results by just searching the listings table by a simple query like: "SELECT * FROM listings WHERE title = 'abc'"; but now what I want do is that I can search for some fields in user table also.

    For eg. currently listings are displayed..but now i should be able to see all listings by searching username of post code. So please tell me how do i go about it ? I know that it can be done using INNER JOIN but i am not sure how to use it.

    Please help.

    Thank you.

  2. #2
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,021
    Mentioned
    53 Post(s)
    Tagged
    2 Thread(s)
    Code:
    select u.name
         , u.postcode
         , l.title
      from users as u
    inner
      join listings as l
        on l.userid = u.id
     where u.postcode like '%CP3%'
        or l.title like '%fanciful%'
    r937.com | rudy.ca | Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"


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
  •