Wrox Home  
Search P2P Archive for: Go

  Return to Index  

pro_vb thread: SQL Urgent help pleeeeeassssseeeeeeee!!!!!


Message #1 by "Nicolas Raitman" <new_world@r...> on Thu, 21 Sep 2000 21:20:39 -0300
Hi, Nicolas Raitman:

Q1:
SELECT clientes.cli_codigo, clientes.cli_nombre
FROM Clientes INNER JOIN ClientesSinOperarPrevio ON Clientes.CLI_Codigo <>
ClientesSinOperarPrevio.Cliente
ORDER BY clientes.cli_codigo;

Ans:
This SQL is slow because it will get all records from 2 tables as "no
join" (if table1 has 100 records and table2 has 50, it will get
50*100=5000) first, then it compare the "CLI_Codigo" <> "Cliebte" (just like
where clause).

If you want find what inside one table but not in the other, try to use
"left join" or "right join". If you want to find outstanding records from
both tables, you can create 2 queries then union them (union is slow too).
I recommand you create another table to store the results from 2 queries.



Q2:
This one never ends... I mean no result is shown to me, is like the
machine
doesnt responde any more. Remember that the table Clientes has 7500
records
and the table Ventas has around 40000. When I run the same code within
tables with only ten records it worked fine, is there any way to optimize
this query, of course, in the case it is ok.

SELECT Clientes.cli_id, clientes.cli_nombre, clientes.loc, clientes.tel,
clientes.prov
FROM Clientes
WHERE Clientes.cli_id not in (Select DISTINCT ventas.ven_cliente from
Ventas
where ventas.ven_mes = 5 and Ventas.VEN_Anio=2000 );

Ans:
You try to use "In" funtion in this query which is only good for small
amount. What it will do is it will the SQL statement inside In() will
return an array (memory cosuming) to In() and In() will retun as a where
clause. So if this SQL statement return huge amount records, then your
system will hanging there.

The solution is you can change the first SQL (inside In()) to a make table
SQL or an append SQL. Use that result table inner join your Clientes
table, and you should get a much faster result.

Darren Li
tajendarrenli@h...

ps. I'm looking for a new job. If your company has any open positions, I
would like to try.


  Return to Index