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 :

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   

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 IDX Inner Inner Use User WHERE idx.user_id = '2' and idx.user_id2 = users.id by idDDate by DESC

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:

 < 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  IDAdet DESC   

but it is not working, I think the query should include both union and join ...

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:

  (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);   

The query returns data from both tables, and orders them properly: I created it

Comments

Popular posts from this blog

excel vba - How to delete Solver(SOLVER.XLAM) code -

github - Teamcity & Git - PR merge builds - anyway to get HEAD commit hash? -

ios - Replace text in UITextView run slowly -