# Help me with a query

**URL:** <https://forum.kirupa.com/t/help-me-with-a-query/218322>\
**Category:** Uncategorized\
**Created:** [March 6, 2007, 8:04pm UTC](https://forum.kirupa.com/t/help-me-with-a-query/218322 "2007-03-06T20:04:00Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![alapimba](https://avatars.discourse-cdn.com/v4/letter/a/ea666f/32.png) [@alapimba](https://forum.kirupa.com/u/alapimba)\
**Post date:** [March 6, 2007, 8:04pm UTC](https://forum.kirupa.com/t/help-me-with-a-query/218322/1 "2007-03-06T20:04:00Z")

</div>

Hello,  
i have 2 tables, socios and socios\_img, it’s a db for members of car club.  
The first table is where i have the id, name, make(of the car), year and a little text.  
The second table i have id, id\_socio(the same number of the 1st table so i can join them) and then i have foto\_thumb and foto\_big.  
Now i wanted to do a query where the result would be: id, name, foto\_thumb(only the first foto from that specific member).  
Basicly i want to display everything from the first table but with an image from the car of the member, but the pictures are only on the second table… and i want only the first picture from each member because the second table has more than 1 picture from each member  
I hope i explain everything clear 🙂

```auto
CREATE TABLE `socios` (
  `id` tinyint(4) NOT NULL auto_increment,
  `nome` tinytext collate latin1_bin NOT NULL,
  `carro` tinytext collate latin1_bin NOT NULL,
  `ano` tinytext collate latin1_bin NOT NULL,
  `texto` text collate latin1_bin NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_bin AUTO_INCREMENT=3 ;
CREATE TABLE `socios_img` (
  `id` tinyint(4) NOT NULL auto_increment,
  `id_socio` tinyint(4) NOT NULL default '0',
  `foto_thumb` tinytext collate latin1_bin NOT NULL,
  `foto_big` tinytext collate latin1_bin NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_bin AUTO_INCREMENT=16 ;

```

let me give you an example:

table socios:  
id | nome | carro | ano | texto  
1 | Rogério Machado | Fiat 600D | 1970 | É amarelo e é muito giro  
2 | Margarida | fiat 600 | 1960 | vermelho descapotavel

table socios\_img  
id | id\_socio | foto\_thumb | foto\_big  
15 | 2 | img/socios/thumb\_2\_Tras.jpg | img/socios/big\_2\_Tras.jpg  
14 | 2 | img/socios/thumb\_2\_Por do sol.jpg | img/socios/big\_2\_Por do sol.jpg  
13 | 1 | img/socios/thumb\_1\_Nenufares.jpg | img/socios/big\_1\_Nenufares.jpg  
11 | 1 | img/socios/thumb\_1\_Inverno.jpg | img/socios/big\_1\_Inverno.jpg

as you see the user rogerio has on db socios\_img 2 images… (id 15 and id 14)  
user margarida has on db socios\_img 2 images too…(id 13 and id 11)

I want to have as result:  
1 | Rogério Machado | Fiat 600D | 1970 | É amarelo e é muito giro | 15 | 2 | img/socios/thumb\_2\_Tras.jpg | img/socios/big\_2\_Tras.jpg  
2 | Margarida | fiat 600 | 1960 | vermelho descapotavel | 13 | 1 | img/socios/thumb\_1\_Nenufares.jpg | img/socios/big\_1\_Nenufares.jpg  
an nothing else.  
How can i do this? :cool:
