List:General Discussion« Previous MessageNext Message »
From:Peter Brawley Date:March 18 2006 3:05pm
Subject:Re: select from multiple tables
View as plain text  
Miguel

 >   What i need is to list all the products and show the type name of 
each of them.

What you need is a join 
(http://dev.mysql.com/doc/refman/5.0/en/join.html), eg:

SELECT t.id, t.id_type, t.name, t.desc, t.price, p.name
FROM tbl AS t
INNER JOIN products AS p USING (id)

PB

-----

Miguel Vaz wrote:
>
>     Hi guys,
>
>     I am kinda new to mysql and on my endeavour to build a backend for 
> a site i am building, i need to fetch data from a couple of tables, 
> but dont know how to do it with a single select.
>     Heres the problem:
>
>     first table (products):
>
>     id
>     id_type
>     name
>     desc
>     price
>
>     second table (types):
>
>     id_types
>     name
>
>
>     What i need is to list all the products and show the type name of 
> each of them. On the products table, on the "id_type" field, i have 
> only a number pointing to its type on the "types" column, what i want 
> to know is how i can do a select to fetch all the product records and 
> replace the number on "id_type" with its equivalente name from the 
> "types" table.
>
>     Sorry if i cant explain it correctly, but heres an example:
>
>     table products:
>
>     id    id_type    name    desc    price
>     1    2    prod1    blah    45
>
>     table types:
>
>     id_type        name
>     1        razor
>     2        string
>
>     I want the list to show:
>
>     prod1    string    blah    45
>
>
>     Thanks,
>
>     Miguel
>
>
Thread
select from multiple tablesMiguel Vaz18 Mar
  • Re: select from multiple tablesPeter Brawley18 Mar