Problem selecting values

Posted on 2005-04-11
Last Modified: 2009-12-16
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
Question by:acslater
    LVL 4

    Expert Comment

    Hi acslater,
    > now how to implement the query to just disp

    This is be done by joining tables

    for more information:

    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
    LVL 32

    Expert Comment

    SELECT r.*
    FROM reservation AS r
    LEFT JOIN car AS c ON r.car_id =
    WHERE c.status = 'Available'
    LVL 2

    Expert Comment

    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";

    Author Comment

    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
    LVL 32

    Accepted Solution

    "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
    LVL 2

    Assisted Solution

    $query = "select reservation.*, car.status from reservation,car WHERE reservation.carid=car.carid and car.status = 'available' ORDER BY reservation.OrderID";

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    What Security Threats Are You Missing?

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Introduction Many web sites contain image galleries; a common design for these galleries includes a page with a collection of thumbnail images.  You can click on each of the thumbnail images to see the larger version of the image.  This is easily i…
    This article will explain how to display the first page of your Microsoft Word documents (e.g. .doc, .docx, etc...) as images in a web page programatically. I have scoured the web on a way to do this unsuccessfully. The goal is to produce something …
    The viewer will learn how to dynamically set the form action using jQuery.
    This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

    759 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

    9 Experts available now in Live!

    Get 1:1 Help Now