#1
  1. No Profile Picture
    jasj
    Guest
    Devshed Newbie (0 - 499 posts)
    How can I execute an INSERT and SELECT on multiple MySQL tables in a database?

    There seems to be lots of examples and tutorials on performing actions on a single table, but I'm using multiple tables to organize my data and I have no programming experience whatsoever. :P

    Thanks for your time.

    John
  2. #2
  3. No Profile Picture
    thelem
    Guest
    Devshed Newbie (0 - 499 posts)
    There may be a proper way of doing this, but I would just have two INSERT statements and treat the tables seperatly. The user should not notice any differance.

    Lemming
    www.lemnet.com
  4. #3
  5. No Profile Picture
    jpenix
    Guest
    Devshed Newbie (0 - 499 posts)
    Let's say you want all 'field1' from 'table1' and 'field2' from 'table2' where the value of the 'recordid' column (in both tables) matches.

    Your select would look like this:

    SELECT field1.table1, field2.table2 FROM table1, table2 WHERE recordid.table1 = recordid.table2;

    You can see the basics in working with multiple tables - use the *.<tablename> format to specify which table you want to work with. If 'field1' and 'field2' in the example above are unique names, then you can leave off the tablename - SQL is smart enough to figure it out.
  6. #4
  7. No Profile Picture
    Will
    Guest
    Devshed Newbie (0 - 499 posts)
    This is how I INSERT into a SET-type field.
    Instead of this:
    <SELECT NAME="field_Name" MULTIPLE SIZE=3>

    Make you select box an array like this:
    <SELECT NAME="field_Name[]" MULTIPLE SIZE=3>

    That will store the multiple values. Then when you INSERT your data, you want all the values of the array attached with commas(,).
    Your INSERT should look like this:

    $sql = "INSERT INTO TBN_directory VALUES ('$field1','$field2','";
    $sql .= implode(",", $field_Name);

Similar Threads

  1. insert and update 2 tables
    By welly in forum PHP Development
    Replies: 14
    Last Post: February 23rd, 2004, 07:41 AM
  2. Input...Select using multiple tables
    By misterdrogo in forum MySQL Help
    Replies: 1
    Last Post: February 11th, 2004, 04:11 PM
  3. how to insert data from html select
    By tabashishi in forum MySQL Help
    Replies: 2
    Last Post: February 11th, 2004, 12:29 PM
  4. MySQL lock tables problem: mysql hangs?
    By Cyclefreak in forum MySQL Help
    Replies: 0
    Last Post: February 6th, 2004, 07:24 AM
  5. Replies: 1
    Last Post: January 30th, 2004, 06:04 PM

IMN logo majestic logo threadwatch logo seochat tools logo