[mysql][php] Problematic join results from two tables and filtering in php

ano bityu

I am looking for a way to get data about the production process. I have two tables:

production: stores product information

timeline: there are details of the employee and when he made the production step

production:

--------------------------
internal | type of closing
--------------------------
123      | close
122      | open

timeline:
------------------------------------------------
id | internal | employee | date        | step
------------------------------------------------
1  | 123      | E01      | 2017-11-11  | diag
2  | 123      | E03      | 2017-11-12  | rep
3  | 122      | E06      | 2017-11-05  | diag

Steps from the column steps are predetermined (diag,rep,test)

I would like to get a result:

----------------------------------------------------------------------------------------
internal | diag | date_diag  | rep  | date_rep   | test  | date_test  | type of closing
----------------------------------------------------------------------------------------
123      | E01  | 2017-11-11 | E03  | 2017-11-12 | NULL  | NULL       | close
122      | E06  | 2017-11-05 | NULL | NULL       | NULL  | NULL       | open

To filter this result later by date_rep(or)date_test(or)date_diag and type of closing (close/open). How can this be done using Mysql and PHP? With the best performance, because the base is huge.

kiks73

You should use different aliases on the same table, joining the table in a way like this:

SELECT T1.internal, 
       T1.employee, 
       T1.date as date_diag,
       T2.employee as rep,
       T2.date as date_rep,
       NULL,
       NULL,
       P.description
FROM timeline T1
INNER JOIN production P ON T1.internal = P.internal 
LEFT JOIN timeline T2 ON T1.internal = T1.internal and T2.step = 'rep'
WHERE T1.step ='diag'

This is a starting point close enough to the solution.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

PHP/MySQL - Join/Union the results of two tables

From Dev

JOIN two SELECT statement results from two different tables

From Dev

Filtering results of a join between 2 tables

From Dev

MYSQL: Query two tables and join results from second table to an array

From Dev

PIVOT dynamically, Returned results from JOIN of two tables

From Dev

MYSQL JOIN two tables limit results from second table by date

From Dev

MySql multiple select from two tables and join their results to a third table

From Dev

MYSQL: Query two tables and join results from second table to an array

From Dev

Delete information from two join tables in MySQL using php

From Dev

Delete information from two join tables in MySQL using php

From Dev

sql join two tables, with non repeating results

From Dev

Inner join two tables with date results

From Dev

Join from two tables mysql

From Dev

Join data from two tables

From Dev

mySQL multiple select from two tables (filtering)

From Dev

join tables and display all the results php mysql?

From Dev

How can i join two tables after filtering

From Dev

Mysql join results from 2 tables

From Dev

Is possible to join two tables (One Mysql, the other Oracle) from two different servers in PHP?

From Dev

How to join two queries from two tables into one query in PHP code?

From Dev

php mysql query to join two tables

From Dev

How to join two tables and return result in php

From Dev

MySQL join two tables using php

From Dev

PHP: How to join two HTML tables into one?

From Dev

how to Join two mysql tables in php

From Dev

Get MySQL results from two tables

From Dev

How to display search results from two tables?

From Dev

ORMLite - Find union of results from two tables

From Dev

php/sql JOIN two tables of data from $variable created from dropdown selection

Related Related

  1. 1

    PHP/MySQL - Join/Union the results of two tables

  2. 2

    JOIN two SELECT statement results from two different tables

  3. 3

    Filtering results of a join between 2 tables

  4. 4

    MYSQL: Query two tables and join results from second table to an array

  5. 5

    PIVOT dynamically, Returned results from JOIN of two tables

  6. 6

    MYSQL JOIN two tables limit results from second table by date

  7. 7

    MySql multiple select from two tables and join their results to a third table

  8. 8

    MYSQL: Query two tables and join results from second table to an array

  9. 9

    Delete information from two join tables in MySQL using php

  10. 10

    Delete information from two join tables in MySQL using php

  11. 11

    sql join two tables, with non repeating results

  12. 12

    Inner join two tables with date results

  13. 13

    Join from two tables mysql

  14. 14

    Join data from two tables

  15. 15

    mySQL multiple select from two tables (filtering)

  16. 16

    join tables and display all the results php mysql?

  17. 17

    How can i join two tables after filtering

  18. 18

    Mysql join results from 2 tables

  19. 19

    Is possible to join two tables (One Mysql, the other Oracle) from two different servers in PHP?

  20. 20

    How to join two queries from two tables into one query in PHP code?

  21. 21

    php mysql query to join two tables

  22. 22

    How to join two tables and return result in php

  23. 23

    MySQL join two tables using php

  24. 24

    PHP: How to join two HTML tables into one?

  25. 25

    how to Join two mysql tables in php

  26. 26

    Get MySQL results from two tables

  27. 27

    How to display search results from two tables?

  28. 28

    ORMLite - Find union of results from two tables

  29. 29

    php/sql JOIN two tables of data from $variable created from dropdown selection

HotTag

Archive