English 中文(简体)
从两个表中选择数据而不连接
原标题:Selecting data from two tables without joining
  • 时间:2012-05-25 16:52:39
  •  标签:
  • mysql
  • sql

交易内容如下:

表A有A1和A2列

表B有B1、B2、B3列

现在我想从A1和B1列中选择数据(不连接),条件是:-

B3=某个单词,A2=B2

如果不需要打印B1,我会把查询(没有连接)写成:

select A1 from A where A2 in (select B2 from B where B3= someword );

但是我需要同时打印A1和B1,那么,在不使用join和IN的情况下,有可能做到这一点吗???

最佳回答

当你说你需要将输出限制在A2=B2的位置时

您正在指定一个联接。

称之为其他东西并不能改变它的本质。。。用威利的话来说,

“以任何其他名称加入仍然是加入”

说真的,“Join”不是的名称,也不是单词,甚至不是用于应用它的查询中的语法,它是基于两个不同表的值的逻辑谓词或限制或过滤器。如果你需要将输出限制在表1.A2等于表2,B2的位置,那么你就有了一个连接

问题回答

如果没有JOIN,你就无法有效地做到这一点,或者换句话说,你可以使用插入选择>,但这个操作要慢得多,比如JOINJOIN是最好的选择,它是通过编程和数据库编写的。当你把慢速IS卖给他时,你潜在的未来客户不会那么高兴。





相关问题
SQL SubQuery getting particular column

I noticed that there were some threads with similar questions, and I did look through them but did not really get a convincing answer. Here s my question: The subquery below returns a Table with 3 ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

php return a specific row from query

Is it possible in php to return a specific row of data from a mysql query? None of the fetch statements that I ve found return a 2 dimensional array to access specific rows. I want to be able to ...

Character Encodings in PHP and MySQL

Our website was developed with a meta tag set to... <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> This works fine for M-dashes and special quotes, etc. However, I ...

Pagination Strategies for Complex (slow) Datasets

What are some of the strategies being used for pagination of data sets that involve complex queries? count(*) takes ~1.5 sec so we don t want to hit the DB for every page view. Currently there are ~...

Averaging a total in mySQL

My table looks like person_id | car_id | miles ------------------------------ 1 | 1 | 100 1 | 2 | 200 2 | 3 | 1000 2 | 4 | 500 I need to ...