+ Reply to Thread
Results 1 to 3 of 3

Thread: Query a table based on field values from another table

  1. #1
    bsha100 is offline x10Hosting Member bsha100 is an unknown quantity at this point
    Join Date
    May 2009
    Posts
    3

    Query a table based on field values from another table

    Hey everyone,

    I have a little problem with a mysql query. I need to query a database table for 'places' to retrieve the name, and picture associated with the picture. I want to be able to include the location, however location information is contained in a separate database. The location is linked to it's corresponding place by a common field 'location_id'. Does anyone know how to query the location and return the results from the places as well, or vice versa?

    Thanks

  2. #2
    descalzo's Avatar
    descalzo is offline Grim Squeaker descalzo has a brilliant futuredescalzo has a brilliant futuredescalzo has a brilliant future
    Join Date
    Jul 2009
    Location
    Ankh-Morpork
    Posts
    7,636

    Re: Query a table based on field values from another table

    Yes.
    Nothing is always absolutely so.

  3. #3
    misson is offline x10 Spammer misson is a jewel in the rough
    Join Date
    Mar 2008
    Location
    Libertatia
    Posts
    2,506

    Re: Query a table based on field values from another table

    Assuming you meant to ask "how do I query multiple tables in a single query?", the answer is "use joins" (see also "A Visual Explanation of SQL Joins"). If you need more specific help, please post sample code (which in this case would be the table schema (CREATE TABLE) statements and sample data as INSERT statements) along with the desired result for the sample data.
    Last edited by misson; 09-01-2011 at 05:10 PM.
    Be sure to read all pages linked in this post; they have further information that should prove useful. When asking for help, make sure you follow Eric Raymond's and Jon Skeet's guidelines for prompt, accurate responses. Please answer any questions I ask; they're not rhetorical (probably). Any posted code is intended as illustrative example, rather than a solution to your problem to be copied without alteration. Study it to learn how to write your own solution.
    Misson, not Mission.

+ Reply to Thread

Similar Threads

  1. Table-based layout: Threat or Menace?
    By misson in forum Crossfire
    Replies: 3
    Last Post: 05-10-2011, 07:58 PM
  2. SQL query error table
    By koheli59 in forum Free Hosting
    Replies: 0
    Last Post: 04-13-2011, 07:17 AM
  3. SQL moving a field within a table
    By wjh2303 in forum Programming Help
    Replies: 6
    Last Post: 05-28-2009, 06:34 AM
  4. MysQL Query for Master table & child table
    By phpasks in forum Programming Help
    Replies: 8
    Last Post: 08-07-2008, 08:07 AM
  5. row missing in an auto-increment field of DB table
    By anilson1 in forum Programming Help
    Replies: 3
    Last Post: 06-07-2008, 03:47 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers