简体   繁体   English

如何从选择不同的表中排除表

[英]How to Exclude a Table from Select Distinct

I'm going crazy... 我要疯了...

I want to generate an array of tables that will need to pass through a loop, but I don't want the table "ClientData" included. 我想生成一个需要通过循环的表数组,但是我不希望包含“ ClientData”表。 Whatever I do, though, it keeps showing up in the array... 不过,无论我做什么,它都会不断出现在数组中...

I've tried this: 我已经试过了:

SELECT DISTINCT TABLE_NAME FROM INFORMATION_SCHEMA.COLUMNS
WHERE COLUMN_NAME IN ('QuoteID') AND
COLUMN_NAME NOT REGEXP '\\([^\\)]*ClientData.*\\)'
    AND TABLE_SCHEMA='$db';

I've tried this: 我已经试过了:

SELECT DISTINCT TABLE_NAME 
FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_SCHEMA='$db' OR
`COLUMN_NAME` LIKE 'Training%' OR 
`COLUMN_NAME` LIKE 'Development%' OR  
`COLUMN_NAME` LIKE 'Hardware%' OR 
`COLUMN_NAME` LIKE 'MobilityL%'

In this second case, I have tried to use the LIKE function to pull only the tables I need, but it STILL pulls ClientData. 在第二种情况下,我尝试使用LIKE函数仅提取所需的表,但仍会提取ClientData。 I've even added: 我什至还添加了:

`COLUMN_NAME` NOT LIKE 'ClientData'

And every variation of 'Client%'... 以及“客户%”的每个变体...

I'm spent. 我花了。 Would appreciate any help anyone has. 希望任何人都有帮助。


vearutop, Vearutop,

You broke the dam for me, thanks! 您为我打破了水坝,谢谢! I was caught up in Column_name for some reason and should have been thinking Table_name the whole time. 由于某种原因,我陷入了Column_name的困扰,应该一直在思考Table_name。 Embarrassing... 不好意思

I cribbed your Table_name != 'ClientData' and replaced the Column_Name filters with Table_name and it's perfect. 我选择了您的Table_name!='ClientData',并用Table_name替换了Column_Name过滤器,这很完美。 Here's the final: 这是最终的:

SELECT DISTINCT TABLE_NAME 
FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_SCHEMA='$db' OR
TABLE_NAME LIKE 'Training%' OR 
TABLE_NAME LIKE 'Development%' OR  
TABLE_NAME LIKE 'Hardware%' OR 
TABLE_NAME LIKE 'MobilityL%'  AND
TABLE_NAME != 'ClientData'

Using just TABLE_NAME != 'ClientData' wasn't a tight enough filter, as I also needed to filter out some other tables, but this is perfect. 使用TABLE_NAME!='ClientData'不够严格,因为我还需要过滤掉其他一些表,但这是完美的。 Thanks again. 再次感谢。 I'm in my 50th+ hour of consecutive coding to meet a deadline (need to quit volunteering for things!) and this gets me about 2 hours closer to some sleep. 我正处于连续50个小时以上的编码工作中,要赶上截止日期(需要退出志愿服务!),这使我大约需要2个小时才能入睡。

SELECT DISTINCT TABLE_NAME FROM INFORMATION_SCHEMA.COLUMNS
WHERE COLUMN_NAME IN ('QuoteID') AND
TABLE_NAME != 'ClientData'
AND TABLE_SCHEMA='$db';

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM