mysql - Pass result of one query to another query and then merge results of these two queries -


i have following query:

select name string      , count(*) total      , sum(product = 1) product            string                 language = 1            group                  name            order                 total desc            limit 10 

purpose of query report top-10 of strings according occurrence in string table, plus report occurrence in specific product (with id = 1).

i add column result count how many times each string occurs in middle of strings. purpose have table copy indexed fulltext index.

my problem figure out how pass values of string column result query:

select count(name) inall     copy c         match(c.name) against (/*string*/) 

is possible achieve result 1 sql query?

before:                   after:  string total product      string total product inall +-----+-----+------+      +-----+-----+-------+-----+ |blah | 52  |  12  |      |blah | 52  |  12   | 96  | |bleh | 23  |  14  |      |bleh | 23  |  14   | 56  | |bloh | 14  |  11  |      |bloh | 14  |  11   | 34  | +-----+-----+------+      +-----+-----+-------+-----+ 

thanks.

edit

my schema:

create table language (     `id` int not null auto_increment,     `name` varchar(30) not null,     `code` varchar(10) not null,     primary key (`id`) ) engine=innodb charset=utf8 collate utf8_unicode_ci;   create table product (     `id` int not null auto_increment,     `name` varchar(100) not null,     primary key (`id`) ) engine=innodb charset=utf8 collate utf8_unicode_ci;  create table string (     `id` int not null auto_increment,     `label` varchar(200),     `name` text(500) not null,     `language` int not null,     `product` int not null,     primary key (`id`) ) engine=innodb default charset=utf8 collate utf8_unicode_ci;  create table copy (     `id` int not null,     `name` text(500) not null,     primary key (`id`),     fulltext(name) ) engine=myisam default charset=utf8 collate utf8_unicode_ci; 

plus insert, delete, update triggers.

you can try joining string , copy tables:

select count(*) inall, t.string string, t.total total, t.product product copy c inner join (     select name string, count(*) total, sum(product = 1) product     string     language = 1     group name     order count(*) desc     limit 10 ) t on c.name = t.name 

Comments