Select with field of the same name between two tables without connection however approximate values

Asked

Viewed 28 times

0

I have the 3 tables, 'users_teste', 'nps' and 'product', the product table has no relation with the other 2 tables, I need to perform a search comparing the request of the table 'nps' with the request of the table 'product' to count how many products the user has and show in the name of such product.

The problem found is that in the request field of table 'nps' has the following value '523dsagtjhtz' and the request field of table 'product' has the value '523dsagtjhtz V-Gabriel' since the start is equal and it is possible to cross and perform the desired select???

        CREATE TABLE users_teste (
              id int(11) NOT NULL AUTO_INCREMENT unique,
              username varchar(50) NOT NULL,
              cpf varchar(11) NOT NULL unique,
              permission varchar(20) NOT NULL,
              email varchar(200) NOT NULL unique,
              password varchar(200) NOT NULL,
              passwordResetToken varchar(200),
              resetarSenha varchar(200),
              dataCriacao datetime,
              idusuario varchar(200) not null,
              PRIMARY KEY (cpf)
            ) ;
        
        CREATE TABLE nps (
            id_nps integer auto_increment unique,
            solicitacao varchar(20) not null unique,
            notaNps integer,
            comentarioNps varchar(600),
            horaEnvioPesquisa datetime,
            horaRespostaPesquisa datetime,
            statusPesquisa varchar(5) default='0',
            telefone varchar(20) not null,
            nps_users_iden varchar(14) not null,
            primary key(solicitacao,telefone),
            foreign key(nps_users_iden) references users_nps(cpf)
        );
        
        create table produto(
        id_produto_increment integer not null auto_increment unique,
        dataSituacao datetime,
        status varchar(200) not null,
        recusas integer not null,
        id varchar(100) not null ,
        email varchar(200) not null,
        solicitacao varchar(100) not null,
        idproduto integer not null,
        titular varchar(200) not null,
        dataAprovacao datetime not null,
        situacao varchar(100) not null,
        validade datetime,
        nomeProduto varchar(100) not null,
        atendimentoExterno integer not null,
        produto_colaborador integer not null,
        primary key(id,status),
        foreign key(produto_colaborador) references colaborador(idusuario)
        );



 create table colaborador(
    id_colaborador_increment integer not null auto_increment unique,
    idusuario integer not null,
    usuario varchar(200) not null,
    colaborador_unidade integer,
    primary key(idusuario),
    foreign key(colaborador_unidade) references unidade(unidadeExt)
    );
  • 1

    Already tried using the operator like to query?

  • Yes, however I could not, I need to perform a Count, the problem is that to use the like I have to write a value to compare, I want to perform the Count of all requests that is present in table 'nps'

  • has how to perform a select and put a '%' in front in the like condition? For example: product.like request (select .....)%

  • From what I understand just look for the first word .. subst and her friends https://www.codigofonte.com.br/codigos/extraindo-o-primeiro-nome-em-um-campo-com-o-mysql

  • wear like this LIKE CONCAT(NOME-DO-CAMPO, '%')

  • I managed using SELECT SUBSTRING_INDEX(request,' ',1), to list only the first sequence '523dsagtjhtz' and then created a temporary table with the data from select and added the field as Primary key, then made another select between the desired table and the temporary.

Show 1 more comment
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.