I need help with a select query, but before asking the question, I will give a short description of how my system works:

My database has a many-to-many relationship:

```
table product:
prd_cod(pk) //stores the product code ex: 0,1,2
cat_cod(fk) 
prd_name    //stores the product name, ex: tv, gps, notebook

table description_characteristc:
prd_cod(fk) 
id_characteristic(fk)
description //stores the description of the characteristic, ex: sony, 1kg, hj10

table characteristic:
id_characteristic (pk)
name_characteristic //store the name of characteristic, ex: brand, weight, model

```

I have already made a suggest jQuery (in the index.php), where every word I type calls suggest.php, which makes a select and returns the result into the suggestion box in the index: 

```
<?php

header('Content-type: text/html; charset=UTF-8');

$hostname = 'localhost';

$username = 'root';

$password = '';

$dbname = 'cpd';

mysql_connect($hostname, $username, $password)or die('Erro ao tentar conecta o banco 
de dados.');

mysql_select_db( $dbname );

if( isset( $_REQUEST['query'] ) && $_REQUEST['query'] != "" )

{
$q = mysql_real_escape_string( $_REQUEST['query'] );

if( isset( $_REQUEST['identifier'] ) && $_REQUEST['identifier'] == "sugestao")

{
$sql = "SELECT p.prd_name, d.description

FROM product p

INNER JOIN description_characteristc d using (prd_cod)

WHERE '".$q."' like concat(p.prd_name, '%') AND

concat(p.prd_name, ' ', d.description) like concat('".$q."', '%')LIMIT 10";

$r = mysql_query( $sql );

if ( $r )
{

echo '<ul>'."\n";

$cont = 0;

while( $l = mysql_fetch_array( $r ) ){

    $p = $l['nome'];

    $p = preg_replace('/(' . $q . ')/i', '<span style="font-
                     weight:bold;">$1</span>',  

$l['prd_nome'].'&nbsp;'.$l['descricao'].'&nbsp;'.$l['descricao']);

echo "\t".'<li id="autocomplete_'.$cont.'"              
  rel="'.$l['prd_nome'].'.'.$l['descricao'].'">'. utf8_encode( $p ) .'</li>'."\n";
$cont++;
}

echo '</ul>';

}
}

}

?>

```

Here are my questions:

1. Currently when the user types 't', the select brings nothing, only when the user type 'tv' is bringing the result:

`tv led
tv plasm
tv samsumg`

I would like that when the user type 't' the select bring me 'tv'.
2. When you type 'tv plasm' it's bringing the same name\_characteristic twice:

`ex: tv plasm plasm`
3. Currently my select selects the prd\_name and the descriptions of table description\_characteristc:

`tv led`

I would like my select could make a inverse select too, ex: `led tv`.
4. I would like that when the results of the select were shown, there could be a cache feature that shows the order of the most sought for the less sought; remembering that prd\_name stores only 'tv'.

The help I'm looking for can be in the form of select, as in the form of procedure. Also, I can edit the php file.