Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Query Help 2

Status
Not open for further replies.

zinja

MIS
Nov 14, 2002
149
US
I am trying to pull all the field from the properties table, but no fields from the users table where the currently logged in user has the same company_name as the user that is attached to the property. I have a field called userid in the properties table which relates to the id field in the users table. company_name doesn't exist in the properties table. Here is my current sql:
Code:
SELECT * FROM pmr_properties p, pmr_users u WHERE p.sold IS NULL OR p.sold = 0 AND p.active = 1 AND p.userid=u.id AND u.company_name = 'Coldwell Banker Tatman Realtors'

LJ Wilson

My personal saying - Just remember, it can always get worse, and usually will.
 
Hi

I see you composed the query, so what is wrong ?

Just that you want "all the field from the properties table, but no fields from the users table" ?
Code:
SELECT [red]p.[/red]* FROM pmr_properties p, pmr_users u WHERE p.sold IS NULL OR p.sold = 0 AND p.active = 1 AND p.userid=u.id AND u.company_name = 'Coldwell Banker Tatman Realtors'
Or have problem dealing with operator precedence ?
Code:
SELECT * FROM pmr_properties p, pmr_users u WHERE [red]([/red]p.sold IS NULL OR p.sold = 0[red])[/red] AND p.active = 1 AND p.userid=u.id AND u.company_name = 'Coldwell Banker Tatman Realtors'
In the later case I would prefer using the [tt]coalesce()[/tt] function :
Code:
SELECT * FROM pmr_properties p, pmr_users u WHERE [red]coalesce([/red]p.sold[red],0)[/red] = 0 AND p.active = 1 AND p.userid=u.id AND u.company_name = 'Coldwell Banker Tatman Realtors'

Feherke.
 
I agree, thanks for your great post and explaining what I was doing wrong. Here is another star.


LJ Wilson

My personal saying - Just remember, it can always get worse, and usually will.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top