mysql - sql query - how to join/union 3 tables (2 index tables and 1 data table) -
I got 3 tables, 2 index tables and 1 data table
The structure of the tables is like this :
Earlier I had only 2 tables, 1 index table (named 'idx') and 1 data table (name '' user ''), so the query is thus Some were: Select from but now a new index table (name "id x2") was added, the structure is similar to 'idx' (i can not add 'idx' and 'idx 2' to a table, so So now I can not do any query with 3 tables I tried to do something like this: but it is not working, I think the query should include both Any Vs. Doors? Thank you! your'r the correct association seems to go away, but the table should match the structure, Can you give more information? Maybe it should be used? I should do this if I understand your question well: The query returns data from both tables, and orders them properly: I created it User :
id | Name -------- + ----------- 1 | John 2 | Mike 3 James
idx and
idx2 :
user_id | User_id2 | Action | Date --------- + ---------- + ---------- + ---------- 1 | 2 | Message | 2013-03-20 1 | 3 | Message | 2013-03-21 3 | 2 | Chat | 2013-03-21
< Code> SELECT * FROM IDX, IDX2Inner Inner Using User, WHERE (idx.user_id = '2' and idx.user_id2 = users.id) or (idx2.user_id = '2' and idx2.user_id2 = users.id) Order
union and
join ...
(SEX * includes inside users from IDX) WHERE idx.user_id = '2' and Idx User_id2 = users.id) Order by date DISC (WHERE idx2.user_id = '2' and idx2.user_id2 = users.id from the user joining Internal in ADX 2);
Comments
Post a Comment