How to find single row data from joined table in mysql?

ritesh khadka
Product

id | name       | description
1  | one        | test        
2  | two        | test      

Joined Table

id | product_id | is_profile | image 
1  | 1          | 0          | 1.jpg   
2  | 1          | 0          | 2.jpg  
3  | 2          | 0          | 3.jpg  
4  | 2          | 1          | 4.jpg

How to find a single image field from joined table if is_profile!=1 then any data else is_profile=1 particular data with is_profile=1? I am using join query with product table. query:

SELECT Product.*,
  (SELECT joined_table.image
   FROM joined_table
   WHERE joined_table.product_id=Product.id
     AND joined_table.is_profile=IF(joined_table.is_profile = '1', 1, 0) LIMIT 1) product_image
FROM products AS Product
user3470953

You can check

select p.id, p.name, p.description,(select case when
(select jt.image from joined_table jt where 
 jt.product_id=p.id and jt.is_profile=1 limit 1)
is not null
then (select jt.image from joined_table jt where 
 jt.product_id=p.id and jt.is_profile=1 limit 1)
else (select jt.image from joined_table jt where 
 jt.product_id=p.id and jt.is_profile=0 limit 1)
end) as img
from Product p where p.id=2 limit 1

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

how to grab the not equal row from joined table in mysql?

From Dev

Laravel 5.4 - Return single row from joined table

From Dev

MySQL update query on a single table with value from joined table

From Dev

How to migrate data from a single row to an m-to-n-table in MySQL?

From Dev

MySQL select row with two matching joined rows from another table

From Dev

How do you pull all data from a joined table when a related record contains a given value in MySQL?

From Dev

accessing data from a joined table

From Dev

How to retrieve min price via mysql query from a joined table

From Dev

How to concatenate values from joined table in specific order, mysql

From Dev

How to create calculated column from mysql table row data

From Dev

How to change Query to contain data from joined table?

From Dev

MySQL update every single row from a 3 million row table

From Dev

MySQL LIKE from JOIN clause and GROUP_CONCAT returns only one row from joined table

From Dev

mysql table data output in a single row based on the type of the data

From Dev

How to find the max of each row in a table in MYSQL

From Dev

Mysql Query data between date on joined table

From Dev

Fetch Column names from a joined mysql table

From Dev

Mysql - Return max value from joined table

From Dev

Get data from joined table in CakePHP

From Dev

view data from joined table in database

From Dev

Unable to select data from another joined table

From Dev

How to insert multiple data of same name from single form in multiple row of same column of table

From Dev

How to combine data from one table where there are duplicate values into a single row?

From Dev

How to insert multiple data of same name from single form in multiple row of same column of table

From Dev

How to select data from several rows in a single table in one result row?

From Dev

How to combine data from one table where there are duplicate values into a single row?

From Dev

How do I write a single row of data into a postgresql table from R?

From Dev

Doctrine Inheritance - Single_Table inheritade from Joined table

From Dev

Doctrine Inheritance - Single_Table inheritade from Joined table

Related Related

  1. 1

    how to grab the not equal row from joined table in mysql?

  2. 2

    Laravel 5.4 - Return single row from joined table

  3. 3

    MySQL update query on a single table with value from joined table

  4. 4

    How to migrate data from a single row to an m-to-n-table in MySQL?

  5. 5

    MySQL select row with two matching joined rows from another table

  6. 6

    How do you pull all data from a joined table when a related record contains a given value in MySQL?

  7. 7

    accessing data from a joined table

  8. 8

    How to retrieve min price via mysql query from a joined table

  9. 9

    How to concatenate values from joined table in specific order, mysql

  10. 10

    How to create calculated column from mysql table row data

  11. 11

    How to change Query to contain data from joined table?

  12. 12

    MySQL update every single row from a 3 million row table

  13. 13

    MySQL LIKE from JOIN clause and GROUP_CONCAT returns only one row from joined table

  14. 14

    mysql table data output in a single row based on the type of the data

  15. 15

    How to find the max of each row in a table in MYSQL

  16. 16

    Mysql Query data between date on joined table

  17. 17

    Fetch Column names from a joined mysql table

  18. 18

    Mysql - Return max value from joined table

  19. 19

    Get data from joined table in CakePHP

  20. 20

    view data from joined table in database

  21. 21

    Unable to select data from another joined table

  22. 22

    How to insert multiple data of same name from single form in multiple row of same column of table

  23. 23

    How to combine data from one table where there are duplicate values into a single row?

  24. 24

    How to insert multiple data of same name from single form in multiple row of same column of table

  25. 25

    How to select data from several rows in a single table in one result row?

  26. 26

    How to combine data from one table where there are duplicate values into a single row?

  27. 27

    How do I write a single row of data into a postgresql table from R?

  28. 28

    Doctrine Inheritance - Single_Table inheritade from Joined table

  29. 29

    Doctrine Inheritance - Single_Table inheritade from Joined table

HotTag

Archive