?
Solved

query for two tables

Posted on 2004-08-06
7
Medium Priority
?
207 Views
Last Modified: 2010-04-06
i have two table, one for project name and the type of project like this

Project

ID     project_name
         
1      project one
2      project two
3      project three

Type

typeid          ID     type_project   minprice         maxprice
1        1        residential     2,717,000.00      4,197,000.00
2        1      commercial     408,000.00        983,000.00
3        1      industrial       399,600.00       1,000,000.00  
4        2      commercial     691,000.00         2,273,500.00
5        2      residential     263,000.00        2,267,000.00
6        3      commercial       194,700.00        341,500.00

my query is
Select * from project,type where type.minprice >= 500000 and type.maxprice <= 1000000 and project.ID = type.ID order by project.project_name asc"

it should display these:

2     1      commercial     408,000.00     983,000.00 = because 983,000.00 is less than 1000000

3     1      industrial    399,600.00          1,000,000.00  = because 1,000,000.00 is equal to 1000000

4     2      commercial     691,000.00         2,273,500.00 = because 691,000.00 is less than 1000000


what should be my query?

pls. help
       
0
Comment
Question by:amerliwayway
  • 2
  • 2
5 Comments
 

Author Comment

by:amerliwayway
ID: 11734299
the DB i am using is MS ACCESS
0
 
LVL 35

Expert Comment

by:YZlat
ID: 11734783
Select Type.typeid,Project.ID,Type.type_project,Type.minprice,Type.maxprice from project,type where type.minprice >= 500000 OR type.maxprice <= 1000000 and project.ID = type.ID order by project.project_name asc"
0
 
LVL 35

Expert Comment

by:YZlat
ID: 11734789
opps, replace OR with AND
0
 
LVL 7

Accepted Solution

by:
Tanglin05 earned 300 total points
ID: 11736631
SELECT Type.typeID, Project.ID, Type.type_project, Type.minprice, Type.maxprice

FROM Type INNER JOIN Project ON Type.ID = Project.ID

WHERE (Type.minprice >= 500000 AND Type.maxprice <= 1000000)

ORDER BY Project.project_name;
0
 
LVL 7

Expert Comment

by:Tanglin05
ID: 11736659
It is always better for security and performance not to use the "*" wildcard in database select statements. Otherwise, the INNER JOIN is a more graceful way of connecting your two tables- where all records with matching values will be returned.

To learn more about forming SQL statements, this web site is VERY helpful and easy to use:

http://www.w3schools.com/sql/default.asp
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Styling your websites can become very complex. Here I'll show how SASS can help you better organize, maintain and reuse your CSS code.
Without even knowing it, most of us are using web applications on a daily basis.  In fact, Gmail and Yahoo email, Twitter, Facebook, and eBay are used by most of us daily—and they are web applications. We generally confuse these web applications to…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question