Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How can I call sub-query?

Status
Not open for further replies.

rejoice

MIS
Jun 5, 2002
42
MY
How can I call sub-query in MYSQL? For example:

SELECT * FROM pr_groups WHERE pr_groups.group_id=(SELECT groups_id FROM pr_items)

Besides, does mySQL allow creation of query file like MS-Access, so that I can call the query file from another query statement. For example:

SELECT * FROM query_file_name
 
How can I call sub-query in MYSQL?

You can't. It is not supported in any released version of Mysql. (Only alpha-test versions.)

Code:
SELECT pr_groups.* FROM pr_groups join pr_items
on pr_groups.group_id = pr_items.groups_id

should yield the same result (as you use = in the comparison).

does mySQL allow creation of query file like MS-Access

No.
 
What Mysql claims on that page is not true.

Code:
create table t1(c1 int);
insert into t1 values(1);
insert into t1 values(1);
create table t2(c1 int);
insert into t2 values(1); 
insert into t2 values(1); 

select * from t1 where c1 in (select c1 from t2);

select t1.* from t1 join t2 on t1.c1 = t2.c1;

These two select statement will not give the same result.
 
swampBoogie:

On the page titled " Rewriting Subqueries for Earlier MySQL Versions", the MySQL online manual states, "It is often possible to rewrite a query without a subquery[/b]"

So you're saying that isn't true?

Want the best answers? Ask the best questions: TANSTAAFL!!
 
no, he's just giving a counterexample

"It is often possible to rewrite a query without a subquery"

often, but not always

the page cited seemed to imply that those two queries were equivalent

they aren't always

it depends on the data





rudy
SQL Consulting
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top