I changed it...
they were |     AND relAB.B='a1' in the other examples

|  SELECT QB.id, QB.ref, QB.question from QB, relAB
|       WHERE QB.ref=relAB.B
|       AND relAB.A='a1'
|
|  SELECT DISTINCT QB.id, QB.ref, QB.question from QB, relAB
|       WHERE QB.ref=relAB.B
|       AND relAB.A='a1'
|
|  SELECT * from QB as tbl1
|       LEFT JOIN relAB as tbl2
|       ON tbl2.B=tbl1.ref
|       where tbl2.A='a1'

-----Original Message-----
From: Nuno Teixeira [mailto:[EMAIL PROTECTED]]
Sent: Saturday, February 09, 2002 12:45 PM
To: Butch Bean
Cc: [EMAIL PROTECTED]
Subject: Re: is possible 1 query with 2 selects?



  Hi,

  Ok. Now I don't get syntax error but I don't get any results.

  Anyway, I think that it is something like your examples.

  Again, I need to get this results with only one query:

  1st: get results from relAB to see QB relations:

  SELECT B from relAB WHERE A='a1';

  results:
  +------+
  | B    |
  +------+
  | b1   |
  | b2   |
  | b3   |
  +------+

  (This results said that only QB b1, b2 and b3 refs are related to 'a1')

  2nd: get only b1, b2, b3 from QB:

  SELECT * FROM QB WHERE ref in ('b1','b2','b3');

  results:
  +----+------+----------+
  | id | ref  | question |
  +----+------+----------+
  |  1 | b1   | qb1      |
  |  2 | b2   | qb2      |
  |  3 | b3   | qb3      |
  +----+------+----------+


  I'm trying to adapt your examples to see if I can get it to work.

  Thanks again,

  Nuno Teixeira


On Sat, Feb 09, 2002 at 12:16:40PM -0500, Butch Bean wrote:
| Nuno,
|
| I think these examples will work OK for what you want...
|
| Butch
|
|  SELECT QB.id, QB.ref, QB.question from QB, relAB
|       WHERE QB.ref=relAB.B
|       AND relAB.B='a1'
|
|  SELECT DISTINCT QB.id, QB.ref, QB.question from QB, relAB
|       WHERE QB.ref=relAB.B
|       AND relAB.B='a1'
|
|  SELECT * from QB as tbl1
|       LEFT JOIN relAB as tbl2
|       ON tbl2.B=tbl1.ref
|       where tbl2.B='a1'
|
|
| -----Original Message-----
| From: Nuno Teixeira [mailto:[EMAIL PROTECTED]]
| Sent: Saturday, February 09, 2002 11:18 AM
| To: Butch Bean
| Cc: [EMAIL PROTECTED]
| Subject: Re: is possible 1 query with 2 selects?
|
|
|
|   Hi,
|
|   I try it and I get a syntax error:
|
|   "You have an error in your SQL syntax near 'on tbl2.A=tbl1.A where
|   tbl2.A='a1'' at line 1"
|
|   My tables structure are:
|
|   show fields from QB;
|   +----------+-------------+------+-----+---------+----------------+
|   | Field    | Type        | Null | Key | Default | Extra          |
|   +----------+-------------+------+-----+---------+----------------+
|   | id       | int(11)     |      | PRI | NULL    | auto_increment |
|   | ref      | char(3)     | YES  |     | NULL    |                |
|   | question | varchar(30) | YES  |     | NULL    |                |
|   +----------+-------------+------+-----+---------+----------------+
|
|   show fields from relAB;
|   +-------+---------+------+-----+---------+----------------+
|   | Field | Type    | Null | Key | Default | Extra          |
|   +-------+---------+------+-----+---------+----------------+
|   | id    | int(11) |      | PRI | NULL    | auto_increment |
|   | A     | char(3) | YES  |     | NULL    |                |
|   | B     | char(3) | YES  |     | NULL    |                |
|   +-------+---------+------+-----+---------+----------------+
|
|
|   Thanks for your help,
|
|   Nuno Teixeira
|
| On Sat, Feb 09, 2002 at 08:49:44AM -0500, Butch Bean wrote:
| | I don't know you table structure but something like this would do it...
| |
| | SELECT * from QB as tbl1
| | JOIN relAB as tbl2
| | ON tbl2.A=tbl1.A
| | where tbl2.a='a1'
| |
| | Butch Bean
| |
| | -----Original Message-----
| | From: Egor Egorov [mailto:[EMAIL PROTECTED]]
| | Sent: Saturday, February 09, 2002 7:24 AM
| | To: [EMAIL PROTECTED]
| | Subject: is possible 1 query with 2 selects?
| |
| |
| | Nuno,
| |
| | Friday, February 08, 2002, 11:04:51 PM, you wrote:
| |
| |
| | NT>   Hello to all,
| |
| | NT>   I'm trying to make a query with only one command but I can't see
how
| | to do
| | NT>   it.
| |
| | [skip]
| |
| | NT>   What I want to do is get a list from table QB related to an item
| from
| | NT>   table QA:
| |
| | NT>         For example, get a list from QB related to item 'a1':
| |
| | NT>         1. select B from relAB where A='a1';
| |
| | NT>         (result: b2, b3, b4)
| |
| | NT>         2. select * from QB where ref in ('b2','b3','b4');
| |
| | NT>         (result: only 'a1' related items)
| |
| | NT>   There is a way of make this query with only one command?
| |
| | NT>   Something like:
| |
| | NT>         1. select * from QB where ref in (select B from relAB where
| | A='a1');
| |
| | MySQL doesn't curently support sub-selects, look at:
| |       http://www.mysql.com/doc/A/N/ANSI_diff_Sub-selects.html
| |
| | It is in our plans to support sub-selects in future:
| |       http://www.mysql.com/doc/T/O/TODO_MySQL_4.1.html
| |
| | NT>   Please help me in this matter.
| | NT>   Thanks very much,
| |
| |
| |
| |
| |
| | --
| | For technical support contracts, goto https://order.mysql.com/
| | This email is sponsored by Ensita.net http://www.ensita.net/
| |    __  ___     ___ ____  __
| |   /  |/  /_ __/ __/ __ \/ /    Egor Egorov
| |  / /|_/ / // /\ \/ /_/ / /__   [EMAIL PROTECTED]
| | /_/  /_/\_, /___/\___\_\___/   MySQL AB / Ensita.net
| |        <___/   www.mysql.com
| |
| |
| |
| | ---------------------------------------------------------------------
| | Before posting, please check:
| |    http://www.mysql.com/manual.php   (the manual)
| |    http://lists.mysql.com/           (the list archive)
| |
| | To request this thread, e-mail <[EMAIL PROTECTED]>
| | To unsubscribe, e-mail
| | <[EMAIL PROTECTED]>
| | Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php
| |
| |
| |
| | ---------------------------------------------------------------------
| | Before posting, please check:
| |    http://www.mysql.com/manual.php   (the manual)
| |    http://lists.mysql.com/           (the list archive)
| |
| | To request this thread, e-mail <[EMAIL PROTECTED]>
| | To unsubscribe, e-mail
| <[EMAIL PROTECTED]>
| | Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php
| |
|
| --
| Nuno Teixeira
| pt-quorum.com
|
| /*
| PGP Public Key:
| http://www.pt-quorum.com/pgp/nunoteixeira.asc
| Key fingerprint:
| 8C2C B364 D4DC 0C92 56F5  CE6F 8F07 720A 63A0 4FC7
| */
|
| ---------------------------------------------------------------------
| Before posting, please check:
|    http://www.mysql.com/manual.php   (the manual)
|    http://lists.mysql.com/           (the list archive)
|
| To request this thread, e-mail <[EMAIL PROTECTED]>
| To unsubscribe, e-mail
| <[EMAIL PROTECTED]>
| Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php
|
|

--
Nuno Teixeira
pt-quorum.com

/*
PGP Public Key:
http://www.pt-quorum.com/pgp/nunoteixeira.asc
Key fingerprint:
8C2C B364 D4DC 0C92 56F5  CE6F 8F07 720A 63A0 4FC7
*/


---------------------------------------------------------------------
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/           (the list archive)

To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php

Reply via email to