-1

I have two MySql tables:

 users(id_user, name, age, gender ).

 ways(#id_user,id_way,  start, end, date).

What I want is to retrieve all the ways with their corresponding users details. So my result would be like this:

 id_way  | start  | end    | date       | id_user  | name  | age   | gender
---------------------------------------------------------------------------
 2       | place1 | place2 | 12/06/2013 | 145      | john  | 28    | m
Jonathan Hall
  • 75,165
  • 16
  • 143
  • 189

1 Answers1

3

Have you tried JOIN?

SELECT ways.id_way, ways.start, ways.end, ways.date, users.* 
FROM ways JOIN users USING (id_user)
PinnyM
  • 35,165
  • 3
  • 73
  • 81
  • can i do more than a single JOIN ? i mean can i edit the query so i can retrieve from table preferences(id_pref, #id_user, value) so the result would be retrieving each way with its corresponding user including their preferences. – brahmi maher May 22 '13 at 17:56
  • You can certainly have multiple JOINs. In this case, since it may be possible for user to have no preferences, you would need to use a LEFT OUTER JOIN rather than the standard (INNER) JOIN. You may also need to pivot the data if you want all of a user's preferences to be returned in a single row. Open another question if you need help with this. – PinnyM May 22 '13 at 18:05
  • yes, thanks @PinnyM , things are more clear now. i actually want to join the 3 tables to do manipulate the data easily on my web site using JSON objects. – brahmi maher May 22 '13 at 18:26