BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

MySQL 3.X SQL question

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi Databases (SQL Servers)
View previous topic :: View next topic  
Author Message
Curt Krueger
Guest





PostPosted: Tue Dec 02, 2003 4:21 am    Post subject: MySQL 3.X SQL question Reply with quote



I have two tables, a Cities table and a lendersInCities table

Cities table has the following fields:

id (int), state(varchar), cityname(varchar)

LendersInCities Table fields:

id (int), cityid(int), lenderid(int)

What I'm wanting is SQL that will give me the remaining cities (cities not
in the lendersincities table) by lenderID.

For example, I pick lenderID "1". I would like the SQL that would give me
the cities NOT posted into the LenderInCities Table.

MySQL (ver 3) does not support sub selects.

This is what I have, but it flakes out for some reason?

select cities.CityName, cities.state, lendersincities.* from cities,
lendersincities where (lendersincities.lenderid = :lenderID) and
(lendersincities.cityid <> cities.id)

Any help would be appreciated... I'm thinking I can't see the forest
through the trees! It's been a long day, any help would be appreciated!

Curt


Back to top
George Christoforakis
Guest





PostPosted: Tue Dec 02, 2003 7:27 am    Post subject: Re: MySQL 3.X SQL question Reply with quote



What's the error message?
George Christoforakis.

"Curt Krueger" <ckrueger (AT) NOSPAMdigitalaxiom (DOT) com> wrote

Quote:

I have two tables, a Cities table and a lendersInCities table

Cities table has the following fields:

id (int), state(varchar), cityname(varchar)




Back to top
Curt Krueger
Guest





PostPosted: Tue Dec 02, 2003 1:49 pm    Post subject: Re: MySQL 3.X SQL question Reply with quote



"George Christoforakis"

Quote:
What's the error message?
George Christoforakis.


Hi George,
It does not give me an error, it gives me erroneous results. When I had
just a few (2 lenders) "lenders" in the lendersinCities table, all was well,
now it produces double (two city names) cities for cities that should be
removed (if the logic in the query was correct). Distinct won't do it
because the cities that should not be in there are.

Here's the SQL again:

select cities.cityName, cities.state, lendersincities.* from cities,
lendersincities where (lendersincities.lenderid = :lenderID) and
(lendersincities.cityid <> cities.id)

thanks,
Curt



Back to top
George Christoforakis
Guest





PostPosted: Wed Dec 03, 2003 8:28 am    Post subject: Re: MySQL 3.X SQL question Reply with quote

try the group by clause.
George Christoforakis.

"Curt Krueger" <ckrueger (AT) NOSPAMdigitalaxiom (DOT) com> wrote

Quote:

"George Christoforakis"

What's the error message?
George Christoforakis.


Hi George,
It does not give me an error, it gives me erroneous results. When I
had
just a few (2 lenders) "lenders" in the lendersinCities table, all was
well,





Back to top
George Christoforakis
Guest





PostPosted: Wed Dec 03, 2003 8:37 am    Post subject: Re: MySQL 3.X SQL question Reply with quote

There are a few help lines in the mysql manual which explain how to use the
subselect substitution in versions < 4.1.x
Version 4.1.x alpha supports subselects. I had something like that you want
to do and I changed to 4.1 alpha.

George Christoforakis.


"Curt Krueger"
Quote:

"George Christoforakis"

What's the error message?
George Christoforakis.


Hi George,
It does not give me an error, it gives me erroneous results. When I
had
just a few (2 lenders) "lenders" in the lendersinCities table, all was
well,
now it produces double (two city names) cities for cities that should be
removed (if the logic in the query was correct). Distinct won't do it
because the cities that should not be in there are.

Here's the SQL again:

select cities.cityName, cities.state, lendersincities.* from cities,
lendersincities where (lendersincities.lenderid = :lenderID) and
(lendersincities.cityid <> cities.id)

thanks,
Curt





Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi Databases (SQL Servers) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.