Solved

query for two tables

Posted on 2004-08-06
7
196 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
7 Comments
 

Author Comment

by:amerliwayway
Comment Utility
the DB i am using is MS ACCESS
0
 
LVL 35

Expert Comment

by:YZlat
Comment Utility
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
Comment Utility
opps, replace OR with AND
0
 
LVL 7

Accepted Solution

by:
Tanglin05 earned 75 total points
Comment Utility
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
Comment Utility
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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Hide or Show Images using checkbox array in mysql database 11 237
wordpress limitations 4 91
MVC and Angular 2 70
Specific format 21 140
Preface In the first article: A Better Website Login System (http://www.experts-exchange.com/A_2902.html) I introduced the EE Collaborative Login System and its intended purpose. In this article I will discuss some of the design consideratio…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…

772 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now