MySQL Lists are EOL. Please join:

List:General Discussion« Previous MessageNext Message »
From:mfatene Date:June 14 2005 5:49pm
Subject:Re: How to write subqueries?
View as plain text  
Hello,
You forgot a parenthesis in the regexp function.
Second, if you construct your query with prepared statements, you can do it :

mysql> insert into vt_partition(pnid) values('01234567890');
mysql> select concat('vt_',pnid) into @tbl from vt_parition where pnid regexp
('^[0-9]{11}$') ;

mysql> set @sql:=concat('select num, theme, intro  from ', @tbl);

mysql> prepare stmt from @sql;
Statement prepared
mysql> execute stmt;
mysql> deallocate prepare stmt;
Query OK, 0 rows affected (0.00 sec)


Hope that helps

N.B. you should have only one pnid to make your query work (UNIQUE pnid), or
LIMIT the result of the subquery by LIMIT 1.

Mathias

Selon admin <bvbn@stripped>:

> Hello!
>
> MySQL v. 4.1.11.
> I'm trying to write a subquery, MySQL says "Error".
>
> select num, theme, intro
> from vt_(select pnid from vt_partition where pnid regexp '^[0-9]{11}$')
> order by date desc, timer desc;
>
> describe vt_parition:
> +----------+--------------+------+-----+----------+----------------+
> | Field    | Type         | Null | Key | Default  | Extra          |
> +----------+--------------+------+-----+----------+----------------+
> | num      | int(11)      |      | MUL | NULL     | auto_increment |
> | partname | varchar(255) |      |     |          |                |
> | pnid     | varchar(11)  |      |     |          |                |
> | timer    | time         |      |     | 00:00:00 |                |
> +----------+--------------+------+-----+----------+----------------+
>
> describe vt_24411620611;
> +-------+--------------+------+-----+------------+----------------+
> | Field | Type         | Null | Key | Default    | Extra          |
> +-------+--------------+------+-----+------------+----------------+
> | num   | int(11)      |      | MUL | NULL       | auto_increment |
> | login | varchar(10)  |      |     |            |                |
> | mail  | varchar(35)  |      |     |            |                |
> | theme | varchar(100) |      |     |            |                |
> | intro | text         |      |     |            |                |
> | text  | text         |      |     |            |                |
> | date  | date         |      |     | 0000-00-00 |                |
> | timer | time         |      |     | 00:00:00   |                |
> +-------+--------------+------+-----+------------+----------------+
>
> "vt_"  is a prefix, "pnid" is a postfix.
> And the name of the table is, for expamle, vt_01234567890.
>
> Where is/are the mistake(s) in my subquery?
> Please explain me how to write a subquery in the right way.
>
> --
> Good luck!
> Vladimir
>
> Please avoid sending me Word or PowerPoint attachments.
> See http://www.gnu.org/philosophy/no-word-attachments.html
>
> --
> MySQL General Mailing List
> For list archives: http://lists.mysql.com/mysql
> To unsubscribe:    http://lists.mysql.com/mysql?unsub=1
>
>


Thread
How to write subqueries?Unknown Sender14 Jun
  • Re: How to write subqueries?SGreen14 Jun
    • RE: How to write subqueries?Rhino14 Jun
  • RE: How to write subqueries?Rhino14 Jun
  • Re: How to write subqueries?mfatene14 Jun
    • Re: How to write subqueries?Unknown Sender14 Jun
      • Re: How to write subqueries?mfatene14 Jun
        • Table fullEmmett Bishop15 Jun
          • Re: Table fullmfatene15 Jun
            • Re: Table fullEmmett Bishop15 Jun
              • Re: Table fullmfatene15 Jun
                • Re: Table fullEmmett Bishop15 Jun
                  • Re: Table fullmos16 Jun
                    • Re: Table fullEmmett Bishop16 Jun
                      • Re: Table fullmfatene16 Jun
        • Re: How to write subqueries?Unknown Sender15 Jun
    • Re: How to write subqueries?Unknown Sender14 Jun