Main Restorations Software Audio/Jukebox/MP3 Everything Else Buy/Sell/Trade
Project Announcements Monitor/Video GroovyMAME Merit/JVL Touchscreen Meet Up Retail Vendors
Driving & Racing Woodworking Software Support Forums Consoles Project Arcade Reviews
Automated Projects Artwork Frontend Support Forums Pinball Forum Discussion Old Boards
Raspberry Pi & Dev Board controls.dat Linux Miscellaneous Arcade Wiki Discussion Old Archives
Lightguns Arcade1Up Try the site in https mode Site News

Unread posts | New Replies | Recent posts | Rules | Chatroom | Wiki | File Repository | RSS | Submit news

  

Author Topic: Need SQL Guru, Question Enclosed  (Read 1028 times)

0 Members and 1 Guest are viewing this topic.

SteveJ34

  • Trade Count: (+9)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 810
  • Last login:January 06, 2024, 12:29:40 am
Need SQL Guru, Question Enclosed
« on: October 25, 2005, 10:23:10 am »
I had someone pose a question to me regarding SQL syntax that I am not well versed enough to answer. I thought someone here may have a greater level of background in this area and might be able to suggest a solution:

Background:

Table 1: Name/Address/Zipcode
Table 2: Low Zip, High Zip Ranges

Data Example:

Table 1:
Steve Johnson, POB xxxx,...., 75052
Jay Dennis, 234 Brittany, ...., 76039

Table 2:
10010, 10030
75000, 76000

The question is how to accomplish a SQL select that extracts the records out of Table 1 that fall within the range of zips in Table 2.

Any clues or someone that might be able to help construct the SQL statement to accomplish?

I look forward to any and all replies.


Jabba

  • D-Hutt
  • Trade Count: (0)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 1643
  • Last login:November 16, 2020, 02:17:20 pm
  • I find your lack of faith...disturbing...
Re: Need SQL Guru, Question Enclosed
« Reply #1 on: October 25, 2005, 10:43:38 am »
At first blush:

SELECT a.*
FROM TABLE1 a, TABLE2 b
WHERE a.zipcode >= b.zipcode_low and a.zipcode <= b.zipcode_high

should do it...This syntax is based on Oracle, but should be generic enough for what you are trying to do. I put it on separate lines for clarity, you should type all on one line in case SQL client does not accept lines broken up...

What database are you using?

« Last Edit: October 25, 2005, 10:45:51 am by Jabba »
Vids:  Home built MAME machine, Crystal Castles. Arkanoid
Pins:   Williams Aztec (working). Stern Nugent (not working...yet), Williams Phoenix (major not working, missing parts.... )

Always on the lookout for buying 90's game with Ramps that need work...

SirPoonga

  • Puck'em Up
  • Global Moderator
  • Trade Count: (+1)
  • Full Member
  • *****
  • Offline Offline
  • Posts: 8188
  • Last login:July 20, 2025, 03:37:24 pm
  • The Bears Still Suck!
Re: Need SQL Guru, Question Enclosed
« Reply #2 on: October 25, 2005, 10:51:25 am »
should do it...This syntax is based on Oracle, but should be generic enough for what you are trying to do. I put it on separate lines for clarity, you should type all on one line in case SQL client does not accept lines broken up...
SQL is SQL, n matter the database.  But yes, some databases have extra syntax.  However, being "broken up" is part of the SQL standard so if it says SQL compliant....


SteveJ, are you assuming 5 digit zipcodes with no alpha characters?

SteveJ34

  • Trade Count: (+9)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 810
  • Last login:January 06, 2024, 12:29:40 am
Re: Need SQL Guru, Question Enclosed
« Reply #3 on: October 25, 2005, 11:21:26 am »
Thanks guys.

By first glance it certainly looks simple enough. I've passed the info along and will report success. I assume by design it will loop through all the records in table 2/b comparing each range?

The database backend in this specific situation I believe is MS SQL.

And yes, the database is strictly US based with the zip range table being only 5 digits.
« Last Edit: October 25, 2005, 11:28:52 am by SteveJ34 »

Jabba

  • D-Hutt
  • Trade Count: (0)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 1643
  • Last login:November 16, 2020, 02:17:20 pm
  • I find your lack of faith...disturbing...
Re: Need SQL Guru, Question Enclosed
« Reply #4 on: October 25, 2005, 12:06:49 pm »
Yeah it will join the two tables. Make sure your Hi Lo table does not have overlapping ranges. If they do, the record (address) may get selected rtwice...If you were adding up sales order, this could do double accounting. Now if it's calculating Sales commission and you are the sales guy, heh, leave it as is
« Last Edit: October 25, 2005, 12:10:28 pm by Jabba »
Vids:  Home built MAME machine, Crystal Castles. Arkanoid
Pins:   Williams Aztec (working). Stern Nugent (not working...yet), Williams Phoenix (major not working, missing parts.... )

Always on the lookout for buying 90's game with Ramps that need work...

Jabba

  • D-Hutt
  • Trade Count: (0)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 1643
  • Last login:November 16, 2020, 02:17:20 pm
  • I find your lack of faith...disturbing...
Re: Need SQL Guru, Question Enclosed
« Reply #5 on: October 25, 2005, 12:09:48 pm »
Vids:  Home built MAME machine, Crystal Castles. Arkanoid
Pins:   Williams Aztec (working). Stern Nugent (not working...yet), Williams Phoenix (major not working, missing parts.... )

Always on the lookout for buying 90's game with Ramps that need work...