Results 1 to 6 of 6
  1. #1
    Join Date
    Oct 2012
    Posts
    3

    Unanswered: How to make this query

    Hi,

    I'm not able to make the following query :

    I have 2 tables - User and Roomapi

    I want to get the email of the User in table User that has the roomapi 605 in table Roomapi.

    Is this possible ?

  2. #2
    Join Date
    Mar 2004
    Posts
    480
    Yes it is possible. You would use a join. This looks like a homework question, more so that you are a new user to the forum. Please show us what you have attempted and we can assist you.

  3. #3
    Join Date
    Oct 2012
    Posts
    3
    Hi,

    Yes I'm very new. sorry ;-)

    Well I had something in mind like this :

    SELECT `name`, `email` FROM `User` WHERE `id` = `user_id` FROM `RoomOption` AND WHERE `RoomApi`=605

    So I want to select them by Id. this is the same in TabelUser and RoomOption.

  4. #4
    Join Date
    Sep 2009
    Location
    San Sebastian, Spain
    Posts
    880
    A SELECT statement can have only 1 WHERE clause and 1 FROM clause.

    Have a look at INNER JOIN's and how they work to join two tables.
    Ronan Cashell
    Certified Oracle DBA/Certified MySQL Expert (DBA & Cluster DBA)
    http://www.it-iss.com
    Follow me on Twitter

  5. #5
    Join Date
    Oct 2012
    Posts
    3
    Well, I googled and found this :

    SELECT Persons.LastName, Persons.FirstName, Orders.OrderNo
    FROM Persons
    INNER JOIN Orders
    ON Persons.P_Id=Orders.P_Id
    ORDER BY Persons.LastName



    So I changed it to :

    SELECT Users.name, Users.email, PokerRoomOption.name
    FROM Users
    INNER JOIN PokerRoomOption
    ON Users.id=PokerRoomOption.user_Id
    ORDER BY Users.name

    Still not working

  6. #6
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    so when you say it isn't working?
    what do you mean
    ..its isn't compiling (ie you are getting an error), if so what is the error
    ..it isn't returning the expected expected results, if so
    have you checked to make certain that there is data that could be returned (ie where there are identical values in users and PokerRoomOptions?
    if there are matching values, are the datatypes the same for ID?
    I'd rather be riding on the Tiger 800 or the Norton

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •