Results 1 to 3 of 3

Thread: [help] Query from two tables?

  1. #1
    77
    posts
    Registered User

    [help] Query from two tables?

    I'm wondering how to go about this? I'm not sure if its even possible or if I need to use a join or something?

    Im using a search facility on my page. When a user types something into the search box I need it to search inside two separate tables. Can this be done?

    The results for the query will be run inside a while statement.

    For the one table I will need to find users names and the other one picture titles.

    I would really appreciate any help?

  2. #2

    Dot syntax for multiple tables

    when you run your query, there is a dot-joined syntax for querying multiple tables:

    The basic structure is this: columnName.tableName

    some examples:
    SELECT username.usertable, pics.pictable FROM usertable, pictable...
    (username = the name of your user name column, and usertable = the name of the table that holds the usernames, pics = the name of the picture title column, pictable = the name of the table holding the picture titles. )

    You can also assign the keyword 'AS' to create an alias for the rows:

    SELECT username.usertable AS user, pics.pictable AS picTitles FROM...

    You can even compare columns from one table to columns of another:

    ...WHERE username.usertable = picowner.pictable...

    Quote Originally Posted by cjj View Post
    I'm wondering how to go about this? I'm not sure if its even possible or if I need to use a join or something?

    Im using a search facility on my page. When a user types something into the search box I need it to search inside two separate tables. Can this be done?

    The results for the query will be run inside a while statement.

    For the one table I will need to find users names and the other one picture titles.

    I would really appreciate any help?

  3. #3
    77
    posts
    Registered User
    I'm not sure how this would work, as I have a WHERE in my query? Let me show you what the two separate queries would look like and maybe you can show me how to put them together. I would really appreciate it!!

    $query1 = "SELECT * FROM items WHERE (item_title LIKE '% $searching %') order by
    item_title asc ";

    $query2 = "SELECT username FROM users WHERE (username LIKE '% $searching %') order
    by username asc";

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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

Home About kirupa.com Meet the Moderators Advertise

 Link to Us

 Credits

Copyright 1999 - 2012