Professional Web Applications Themes

Problem with JOIN and LOCK TABLES - MySQL

Hi Newsgroup! In a more complex SQL request I need to lock the necessary tables. The problem occors when a self referencing table is joined. Here is a short example of what I need and does not work... CREATE TABLE t1 (id INT, ref INT); LOCK TABLES t1 READ; SELECT t1.*,t2.* FROM t1 JOIN t1 AS t2 ON t1.ref = t2.id; UNLOCK TABLES; DROP TABLE IF EXISTS t1; Mysql says: ERROR 1100 (HY000) at line 4: Table 't2' was not locked with LOCK TABLES Sure t2 was not locked. And it can not be locked because there is no table ...

  1. #1

    Default Problem with JOIN and LOCK TABLES

    Hi Newsgroup!

    In a more complex SQL request I need to lock the necessary tables.
    The problem occors when a self referencing table is joined.
    Here is a short example of what I need and does not work...

    CREATE TABLE t1 (id INT, ref INT);
    LOCK TABLES t1 READ;
    SELECT t1.*,t2.* FROM t1 JOIN t1 AS t2 ON t1.ref = t2.id;
    UNLOCK TABLES;
    DROP TABLE IF EXISTS t1;

    Mysql says:
    ERROR 1100 (HY000) at line 4: Table 't2' was not locked with LOCK TABLES


    Sure t2 was not locked. And it can not be locked because there is no table
    t2.

    Is this a bug?

    MySQL Version is 5.0.26
    This is the last stable marked version on my Gentoo Linux System.
    Will try to install 5.0.34 today.

    Regards,
    Andre

    Andre Guest

  2. #2

    Default Re: Problem with JOIN and LOCK TABLES

    On 12 Apr, 10:31, Andre Hinrichs <de> wrote: 

    This is a well doented problem, known as "The person who doesn't
    bother to read the manual" problem!
    Here I copy the very first piece of text on the page dealing with
    Locking Tables (http://dev.mysql.com/doc/refman/5.0/en/lock-
    tables.html).

    LOCK TABLES
    tbl_name [AS alias]
    {READ [LOCAL] | [LOW_PRIORITY] WRITE}
    [, tbl_name [AS alias]
    {READ [LOCAL] | [LOW_PRIORITY] WRITE}]

    Captain Guest

  3. #3

    Default Re: Problem with JOIN and LOCK TABLES

    Captain Paralytic wrote: 

    Uh, shame on me.
    I have read the doc but somehow overlook it.
    Thanks a lot.

    Andre Guest

  4. #4

    Default Re: Problem with JOIN and LOCK TABLES

    On 12 Apr, 11:38, Andre Hinrichs <de> wrote: 

    >
    > Uh, shame on me.
    > I have read the doc but somehow overlook it.
    > Thanks a lot.[/ref]

    No problem. The post was rather tounge in cheek.

    Captain Guest

Similar Threads

  1. join for three tables with grouping
    By john7 in forum MySQL
    Replies: 8
    Last Post: March 3rd, 06:25 AM
  2. Listing join from tables...
    By createmedia in forum Coldfusion Database Access
    Replies: 5
    Last Post: June 5th, 09:02 PM
  3. New to Joines - Inner Join on 4 Tables
    By FusionRed in forum Coldfusion - Getting Started
    Replies: 2
    Last Post: June 14th, 03:14 PM
  4. join on 3 tables for asp output
    By Mike in forum ASP Database
    Replies: 5
    Last Post: October 29th, 06:27 PM

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
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139