首页 > 解决方案 > 如何从通过选择获得的表中的一列中选择表名和值?

问题描述

对不起,听起来很复杂,但解释很简单。我猜答案没有。

在多站点 (WP) 中,我需要从所有名为 xxx_options 的表中的列中获取两个值。

我有脚本从两个模式(wp,wp2)中获取所有表:

SELECT table_name 
FROM information_schema.tables 
WHERE table_schema  like 'wp%' and table_name like '%options';

我得到:

1 wp_11_options
2 wp_12_options 
3 wp2_20_options

我有一个简单的查询来获取值:

SELECT option_value
FROM wp_10_options 
WHERE option_name = 'siteurl'

我需要知道我在哪里有一个网站 URL,所以我需要类似的东西:

1 wp_11_options    https://example1.org
1 wp2_12_options   https://example4.org

或者我可以使用“option_value”中的两个值:

option_id = 1 and 49

或者

option_name = siteurl and upload_path (this file contain de number of the suffix, wp-**10**-options)

所以我可以得到:

1 example1.com      wp-content/blogs.dir/10/files

我猜就像这个超级伪代码:

Select table_name as name, table_name.wp_option_value 
From 
    (SELECT table_name 
     FROM information_schema.tables 
     WHERE table_schema like 'wp%' and table_name like '%options')
Order by table_name

模式:wp y wp2

表:LIKE '%options'

字段:option_id、option_name、option_value

值:option_id = 1 和 49 或 table_name 和 option_name = 'siteurl'

标签: mysqlsqlwordpress

解决方案


推荐阅读