MySQL Finding column values in rows

Tim Bryant

I have a scenario where I need to match values in columns of one table with rows in another.

I have two tables: employee_id and id_entries.

employee_id has the following structure:

    employee_id     id_1    id_2
    1               123      456
    2               789      120
    3               345      678
    4               901      234

id_entries has the following structure:

    employee_name   id_number
    John Doe          123
    Jane Smith        789
    John Doe          456
    Jane Smith        120

I want to be able to match the employee_id field in the employee_id table to employee_name in the id_entries table where there is an entry for both id_1 and id_2.

For example

    employee_id     employee_name    id_1    id_2
    1               John Doe         123     456
    2               Jane Smith       789     120

I've tried several different joins but haven't been able to bring back the correct results. Thanks in advance.

Nir Levy

you need to join it to two instances of id_entries table, one for each id coluomn:

select emploee_id, a.emploee_name, id_1, id_2 form 
 employee_id inner join id_entries as a on employee_id.id_1 = a.id_num
 inner join id_entries as b on employee_id.id_2 = b.id_num
 where a.emploee_name = b.emploee_name

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

MySQL Finding column values in rows

From Dev

Twig: Finding the sum of values of rows in column

From Dev

Finding rows containing a value (or values) in any column

From Dev

finding rows with specific values for a column (matlab)

From Dev

Efficiently finding the count of column values for distinct rows in a dataframe in r

From Dev

Efficiently finding the count of column values for distinct rows in a dataframe in r

From Dev

Finding the rows which has a unique column values in python

From Dev

Select rows with same column values (Mysql)

From Dev

Combine rows and put their values in seperate column in mysql

From Dev

MySQL count rows with two duplicate column values

From Dev

filter rows based on column values in mysql query

From Dev

Combine rows and put their values in seperate column in mysql

From Java

Finding duplicate values in MySQL

From Dev

Finding rows with multiple values in the columns

From Dev

Finding duplicate rows in a MySQL table

From Dev

oracle sql query finding rows with multiple values in 3rd column matching columns 1 and 2

From Dev

Finding combinations of per-column row values such that columns have unique rows

From Dev

Finding duplicate column values in a CSV

From Dev

Finding distinct values in array column

From Dev

Finding duplicate column values in a CSV

From Dev

MySQL: How to find rows with unique column values in a MyISAM table?

From Dev

MySQL - How to delete rows where column does not contain certain values?

From Dev

swap "two" column values in two different rows using mysql

From Dev

Updating multiple rows of a single column with dynamically generated values in mysql

From Dev

How to convert rows data into column data in mysql by avoiding Null Values

From Dev

MySQL - Count rows with equal values but only if name occurs in other column

From Dev

Sum the values of multiple rows with the same column value in MySQL

From Dev

How to UPDATE MySQL Rows with other values in the same column?

From Dev

Finding column creation time in MySQL

Related Related

  1. 1

    MySQL Finding column values in rows

  2. 2

    Twig: Finding the sum of values of rows in column

  3. 3

    Finding rows containing a value (or values) in any column

  4. 4

    finding rows with specific values for a column (matlab)

  5. 5

    Efficiently finding the count of column values for distinct rows in a dataframe in r

  6. 6

    Efficiently finding the count of column values for distinct rows in a dataframe in r

  7. 7

    Finding the rows which has a unique column values in python

  8. 8

    Select rows with same column values (Mysql)

  9. 9

    Combine rows and put their values in seperate column in mysql

  10. 10

    MySQL count rows with two duplicate column values

  11. 11

    filter rows based on column values in mysql query

  12. 12

    Combine rows and put their values in seperate column in mysql

  13. 13

    Finding duplicate values in MySQL

  14. 14

    Finding rows with multiple values in the columns

  15. 15

    Finding duplicate rows in a MySQL table

  16. 16

    oracle sql query finding rows with multiple values in 3rd column matching columns 1 and 2

  17. 17

    Finding combinations of per-column row values such that columns have unique rows

  18. 18

    Finding duplicate column values in a CSV

  19. 19

    Finding distinct values in array column

  20. 20

    Finding duplicate column values in a CSV

  21. 21

    MySQL: How to find rows with unique column values in a MyISAM table?

  22. 22

    MySQL - How to delete rows where column does not contain certain values?

  23. 23

    swap "two" column values in two different rows using mysql

  24. 24

    Updating multiple rows of a single column with dynamically generated values in mysql

  25. 25

    How to convert rows data into column data in mysql by avoiding Null Values

  26. 26

    MySQL - Count rows with equal values but only if name occurs in other column

  27. 27

    Sum the values of multiple rows with the same column value in MySQL

  28. 28

    How to UPDATE MySQL Rows with other values in the same column?

  29. 29

    Finding column creation time in MySQL

HotTag

Archive