• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 217
  • Last Modified:

Problem selecting values

I have two tables reservation and car. I want to select everything from reservation but only display the ones which have status of available. the status field is in the the car table.

Just have simple query at moment as follows:

$query = "select * from reservation ORDER BY OrderID";

Dont know how to implement the query to just display everything in the reservation table that have a status of available in car table
0
acslater
Asked:
acslater
2 Solutions
 
danny_ebbersCommented:
Hi acslater,
> now how to implement the query to just disp

This is be done by joining tables

for more information: http://www.w3schools.com/sql/sql_join.asp

if you want specific examples to help you out,
then please post your table definitions and i'll try to write your query.


Best regards,
Danny Ebbers
0
 
ldbkuttyCommented:
SELECT r.*
FROM reservation AS r
LEFT JOIN car AS c ON r.car_id = c.id
WHERE c.status = 'Available'
0
 
Marvin_CarredoCommented:
The WHERE clause allows you to filter the results from an SQL statement - select, insert, update, or delete statement.

$query = "select * from reservation WHERE status = 'available' ORDER BY OrderID";
0
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.

 
acslaterAuthor Commented:
idbkutty getting a mistake saying invalid query unknown column 'r.car_id' 'on clause'


Marvin: The status field is in the car table so must have to join them.

Danny: I want to select everything from the table reservation but only where status field value in database is Available

Reservation                                                          Car Table
Select everything                                                   Status=Available
0
 
ldbkuttyCommented:
"car_id" should be replaced with the actual column name which related the "car" and "reservation" in "reservation" table!

// Also note that 'Available' is case sensitive comparison
0
 
Marvin_CarredoCommented:
$query = "select reservation.*, car.status from reservation,car WHERE reservation.carid=car.carid and car.status = 'available' ORDER BY reservation.OrderID";
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now