简体   繁体   English

两个MySQL SELECT查询合而为一

[英]Two MySQL SELECT queries in one

I'm working on an Extjs application and I need to get the result of two select queries, encode the results in Json then bind the store containing these results to a gridview. 我正在使用Extjs应用程序,我需要获取两个选择查询的结果,在Json中对结果进行编码,然后将包含这些结果的存储区绑定到gridview。

I have a gridview whith two columns, the first one is "name_scope" and the second is a combobox that should contain the values of the scope (a scope can have multiple values). 我有一个网格视图,其中有两列,第一列是“ name_scope”,第二列是一个组合框,其中应包含范围的值(一个范围可以具有多个值)。 So I've created two tables in mySQL, "scope" and "scope_value", I want to bind scope_name from "scope" table to my first column, then value(s) from "scope_value" table to the combo column. 因此,我已经在mySQL中创建了两个表“ scope”和“ scope_value”,我想将“ scope”表中的scope_name绑定到我的第一列,然后将“ scope_value”表中的值绑定到combo列。

I don't think it's a good idea to make two stores for this matter, so I want to make only one php script that would contain these two queries : 我不认为为此建立两个存储区是一个好主意,因此我只想制作一个包含以下两个查询的php脚本:

SELECT name_scope FROM scope

AND

SELECT value FROM value_scope WHERE name_scope = "'. $name_scope .'"';

These are my tables : 这些是我的桌子:

create table scope (name_scope varchar(50) not null primary key, description varchar(100));
create table value_scope (id_value int not null primary key AUTO_INCREMENT,name_scope varchar(50), value varchar(100), 
            foreign key (name_scope) references scope(name_scope) on delete cascade);

My gridview : 我的GridView:

{
    xtype: 'container',
    id : 'grid_container',

    anchor: '100%',
     forceFit: true,
    items: [{
        xtype: 'gridpanel',
        id: 'scope_grid',
        layout : 'fit',
        frame: true,
        columnLines: true,
        iconCls: 'icon-grid',
        title: 'Prod/Rel added',
        store: 'GetScopeData',
        columns: [{
            id: 'n_scope',
            text: 'Scope',
            flex: 1,
            sortable: true,
            dataIndex: 'name_scope'},

           { header: 'Product Release',
            width: 220,
            fixed: true,
            hideable: false,
            dataIndex: 'value',
            editor: {
                xtype: 'combobox',
                displayField: 'value',
                valueField: 'value',
                mode: 'local',
        editable : false,
                typeAhead: false,
                triggerAction: 'all',
                lazyRender: true,
                emptyText: 'Select action',
                listClass: 'x-combo-list-small'

            }}
]}

What should my php script look like? 我的php脚本应该是什么样的? Please any help would be appreciated. 请任何帮助将不胜感激。

您可以将这两个选择语句组合成一个,例如

SELECT value FROM value_scope WHERE name_scope in (SELECT name_scope FROM scope);

You can make one store with the result set you want - 2 fields (name_scope and value) and combine your query to one using join: 您可以使用所需的结果集-2个字段(name_scope和value)来建立一家商店,并使用join将查询合并为一个:

SELECT scope.name_scope,value  FROM scope
INNER JOIN value_scope ON(scope.name_scope = value_scope.name_scope)
WHERE scope.name_scope = "'. $name_scope .'"';

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

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