doubt with sql query

0

good what happens is that I have a problem to consult a table, I have the typical table products and category where id_categoria would be the attribute that relates the tables

  • what I can not do is bring EVERYTHING from the products table
  • I do not know if it's because the tables are related

    SELECT  *  FROM productos 
    

    and it does not work for me

    I try to do the select without the attribute id_categoria and if it works but I need the query with that value

    thank you very much for your collaboration

        
    asked by Jhonatan Valencia 10.10.2016 в 20:41
    source

    2 answers

    2

    here several queries with only two tables where I have id_categoria in the table products:

      *******************
      *productos        *
      *******************
      *id               *
      *nombre           *
      *descripcion      * 
      *id_categoria     *
      *******************
    
      *******************
      *categorias       *
      *******************
      *id               *
      *nombre           * 
      *descripcion      *
      *******************
    

    Bring all the attributes of all the records in the product table:

    select * from productos
    

    bring all products related to a certain category:

    select * from productos where id_categoria = 3
    

    Bring the names of the products filtered by the name of a category:

    select nombre from productos where id_categoria in ( select id from categorias where nombre like %hogar% )
    
      

    Maybe the one I used is not the structure of your tables, If you put your structure we could help you better. We are waiting for your comments ..

        
    answered by 11.10.2016 / 01:02
    source
    1

    This can happen if you do not use aliases in joins . because it can be a problem to return two columns with the same name.

    SELECT A.CATEGOTYID, A.CATEGORYNAME, B.PRODUCTNAME
    FROM CATEGORY AS A
    INNER JOIN PRODUCT AS B
    ON A.CATEGORYID = B.CATEGORYID
    

    That's how it should work.

        
    answered by 10.11.2016 в 10:53