Results 1 to 3 of 3

Thread: using select in an insert question

  1. #1
    Join Date
    Jul 2006
    Location
    just north of Boston, MA
    Posts
    1,806
    Thanks
    13
    Thanked 72 Times in 72 Posts

    Default using select in an insert question

    is it possible to do an insert query with the values being select statements?

    Code:
    INSERT INTO table(val1, val2) VALUES("SELECT ...", val2);
    or would I need to store the "insert value" to a variable first?

  2. #2
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Code:
    insert into table (col1, col2) values ((select x from sometable), val2);
    should give you no problems so long as the inner SELECT returns only one row.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  3. #3
    Join Date
    Jul 2006
    Location
    just north of Boston, MA
    Posts
    1,806
    Thanks
    13
    Thanked 72 Times in 72 Posts

    Default

    this is sort of similar to my initial question, as some of the fields I am retrieving will than be used later in the insert question I asked above

    I want to grab the info for a part where the part is associated with the printer being displayed, and the client has access to that specific printer.

    Code:
    SELECT part_id, part_info FROM parts WHERE part_info LIKE %$searchTerms% AND  
      MATCH( SELECT printer_id FROM parts_printer WHERE parts.part_id = parts_printer.part_id ) 
      AGAINST($this->printerArray);
    for most parts, the printer_id will actually result in an array or printers, rather than a single printer... will the match clause check each printer in the partprinter array to the usersprinters ($this-printerArray) that is located in the session.

    and also, if it does match one of printers, will it abort the search for that part? because I already know the part belongs to that printer, and if the user has access to the printer, there is no need to check if there the user has access to another printer in the range of possibilities
    Last edited by boogyman; 08-17-2007 at 05:19 PM. Reason: forgot to add the initial search clause now in italic

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
  •