If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > PostgreSQL > query for multiple values

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 01-19-12, 11:17
eponcede eponcede is offline
Registered User
 
Join Date: Jan 2012
Posts: 1
query for multiple values

I am trying to elaborate a query where I want to search for, these values (FB,PH,PN,PU,RN,SM,YQ,0A,1P,).
When I search for 1 values i have no problem, however when I add a second one I get no results.. can anybody guide me on how to fix this... This is my query:
Code:
SELECT
	"TELMEX_CON_ENE"."RAZON_SOCIAL",
  "TELMEX_CON_ENE"."CUENTA",
	"TELMEX_CON_ENE"."SUBCUENTA",
	"TELMEX_CON_ENE"."CLAVE_CONCEPTO",
	"TELMEX_CON_ENE"."MES",
	"SERVICIO"."NOMBRE",
	"PROVEEDOR"."NOMBRE"
FROM 
  public."TELMEX_CON_ENE", 
	public."PROVEEDOR",
	public."SERVICIO"
WHERE 
	"SERVICIO"."NOMBRE" ='TELEFONIA FIJA' AND
	"PROVEEDOR"."NOMBRE" = 'TELMEX' AND
	"TELMEX_CON_ENE"."CLAVE_CONCEPTO" LIKE '%FB-%' AND
	"TELMEX_CON_ENE"."CLAVE_CONCEPTO" LIKE '%PH-%';
Reply With Quote
  #2 (permalink)  
Old 01-20-12, 11:39
futurity futurity is offline
Registered User
 
Join Date: May 2008
Posts: 270
Some comments about your query in general:

* You are not using any JOIN ON conditions to join your tables, which means you are doing a CROSS JOIN for all three of them, which can quickly become very inefficient.

* Your LIKE conditions are also very inefficient: starting the search term with a wildcard (%) means that the database cannot use any indexes on that column and is forced to do a sequential scan of the entire table. If you can, remove the starting wildcard.

As for fixing your query, try:
Code:
WHERE
    "SERVICIO"."NOMBRE" ='TELEFONIA FIJA' 
    AND "PROVEEDOR"."NOMBRE" = 'TELMEX' 
    AND ("TELMEX_CON_ENE"."CLAVE_CONCEPTO" LIKE '%FB-%' 
        OR "TELMEX_CON_ENE"."CLAVE_CONCEPTO" LIKE '%PH-%'
        OR ...)
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On