The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Databases
> Database Management
|
need help making this SQL work
Discuss need help making this SQL work in the Database Management forum on Dev Shed. need help making this SQL work Database Management forum discussing non-database specific SQL. Structured Query Language was designed to be a robust and standardized language for manipulating relational databases.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

November 21st, 2002, 02:46 PM
|
 |
queen of livorna
|
|
Join Date: Nov 2002
Location: California
Posts: 8
Time spent in forums: 36 m 56 sec
Reputation Power: 0
|
|
need help making this SQL work
I have a table that holds information about sitters. I have another table that has information about which sitters are available for what specific cities. I want to select all sitters who are available for a specific city and then order them by the sitter's ranking.
This is what I'm using, which doesn't give me an error, it just doesn't get any records. I'm sure it's something simple I'm doing wrong, but I can't seem to figure it out.
SELECT * FROM tblSitters, tblSitterCity
WHERE tblSitterCity.cityID = '27'
ORDER BY tblSitters.rating
Thanks,
Sarah
|

November 29th, 2002, 11:42 PM
|
 |
Contributing User
|
|
Join Date: Oct 2001
Location: New Zealand
|
|
|
You have no join in the table, eg:
where tblSitterCity.cityID = tblSitter.cityID
|

December 5th, 2002, 01:39 PM
|
 |
Web Developer
|
|
Join Date: Oct 2001
Location: Pennsylvania
Posts: 171
Time spent in forums: < 1 sec
Reputation Power: 0
|
|
|
Also, I'm fairly new to the SQL game, but say the tblSitterCity.cityID field was an integer value, or numeric, or whatever its called on your platform, would the single quotes still be necessary around 27?
|

December 5th, 2002, 03:46 PM
|
 |
queen of livorna
|
|
Join Date: Nov 2002
Location: California
Posts: 8
Time spent in forums: 36 m 56 sec
Reputation Power: 0
|
|
Adding this to the query still doesn't do anything.
Quote: Originally posted by binky
You have no join in the table, eg:
where tblSitterCity.cityID = tblSitter.cityID |
|

December 6th, 2002, 12:15 AM
|
 |
Contributing User
|
|
Join Date: Oct 2001
Location: New Zealand
|
|
|
Doesn't make any sense, what do you get if you try:
SELECT * FROM tblSitterCity cityID = 27;
|

December 6th, 2002, 12:58 PM
|
 |
queen of livorna
|
|
Join Date: Nov 2002
Location: California
Posts: 8
Time spent in forums: 36 m 56 sec
Reputation Power: 0
|
|
|
This is what I get:
mysql> select * from tblSitterCity where cityID = 27;
+--------------+----------+--------+
| sitterCityID | sitterID | cityID |
+--------------+----------+--------+
| 10024 | 103 | 27 |
| 10025 | 109 | 27 |
| 10026 | 115 | 27 |
| 10027 | 110 | 27 |
| 10028 | 117 | 27 |
| 10029 | 111 | 27 |
| 10030 | 112 | 27 |
+--------------+----------+--------+
7 rows in set (0.00 sec)
Tick marks around the 27 gives the same results.
So the query I'm trying now is:
SELECT *
FROM tblSitters, tblSitterCity
WHERE tblSitterCity.cityID = 27 (27 being only an example)
AND tblSitterCity.cityID = tblSitter.cityID
ORDER BY tblSitters.rating DESC
Perhaps I should give more background on the tables
tblSitters (all of our sitters)
sitterID
sitterName
etc....
tblCities (all the cities we provide service to)
cityID
cityName
tblSitterCity (an entry for each sitter and each city they do)
sitterCityID
sitterID
cityID
I have a cityID and I want to select all the sitters that work in that city. It seems pretty simple.
Thanks again for any help you can provide
Sarah
|

December 6th, 2002, 02:33 PM
|
 |
Big Endian
|
|
Join Date: May 2001
Location: Fly-over country
|
|
|
Your query uses tblSitter.cityID which is a field that does not exist. How are you running this query? If you're running a script, it may be that you're not trapping the error message, not that you're getting zero records.
What does this return:
SELECT *
FROM tblSitters a, tblSitterCity b
WHERE b.cityID = 27
AND b.sitterID = a.sitterID
ORDER BY a.rating DESC
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|