Suppose there is such a query:

SELECT t.type_condition AS pay, t.type_condition AS orders, t.type_condition AS news, t.type_condition AS other, s.login AS login, s.telephone AS telephone FROM `vixen_erps_services_sms` s INNER JOIN `vixen_erps_services_type` t ON t.type_id = s.index2 

Can I, after ON write several join conditions? For example:

 SELECT t.type_condition AS pay, t.type_condition AS orders, t.type_condition AS news, t.type_condition AS other, s.login AS login, s.telephone AS telephone FROM `vixen_erps_services_sms` s INNER JOIN `vixen_erps_services_type` t ON t.type_id = s.pay, s.orders, s.news, s.other 

And if not, how? In the fields pay , orders , news , other tables are always for one of the four digits from 1 to 4, for the others - 0. I do this so that instead of numbers in the table on the page the words are displayed. For 1 - 4 - "Enabled", for 0 - "Off". How can I check all the fields?

UPDATE:

There are tables that need to be combined in order to store numbers in a table, and display the contents as words. And this caused me difficulty, I just can’t think of a working request.

enter image description here

enter image description here

enter image description here

  • yes you can, but not like that :-) but what does s.orders, s.news, s.other mean ? with which fields should they be combined? - Grundy
  • added to question - luckydutch
  • um, and how is it in your one column and 0 and Выключен ? - Grundy
  • I want to store in the first table, say, 0, and display the word "Off" on the page. - luckydutch
  • Well, so you show that you have in one table - one line - stores the name , and the other numbers - Grundy

1 answer 1

Simply it is impossible to list the fields in the ON-condition separated by a comma, for their combination you need the operator AND or OR

 SELECT t.type_condition AS pay, t.type_condition AS orders, t.type_condition AS news, t.type_condition AS other, s.login AS login, s.telephone AS telephone FROM `vixen_erps_services_sms` s INNER JOIN `vixen_erps_services_type` t ON t.type_id = s.pay AND t.type_id = s.orders AND t.type_id = s.news AND t.type_id = s.other 

In ON , the same rules apply as after the WHERE keyword.

UPDATE:

However, in your case, you have to perform INNER JOIN for each of the fields (I would even replace it with LEFT JOIN )

 SELECT p.type_condition AS pay, o.type_condition AS orders, n.type_condition AS news, a.type_condition AS other, s.login AS login, s.telephone AS telephone FROM `vixen_erps_services_sms` s LEFT JOIN `vixen_erps_services_type` p ON p.type_id = s.pay LEFT JOIN `vixen_erps_services_type` o ON o.type_id = s.orders LEFT JOIN `vixen_erps_services_type` n ON n.type_id = s.news LEFT JOIN `vixen_erps_services_type` a ON a.type_id = s.other 

Alternatively, you may need subqueries

 SELECT (SELECT type_condition FROM vixen_erps_services_type WHERE type_id = s.pay) AS pay, (SELECT type_condition FROM vixen_erps_services_type WHERE type_id = s.orders) AS orders, (SELECT type_condition FROM vixen_erps_services_type WHERE type_id = s.news) AS news, (SELECT type_condition FROM vixen_erps_services_type WHERE type_id = s.other) AS other, s.login AS login, s.telephone AS telephone FROM `vixen_erps_services_sms` s 
  • it’s rather OR seems to me - Grundy
  • @Grundy, maybe. Cited AND to demonstrate combining several conditions in ON. - cheops
  • It works as it should. Thank you very much. - luckydutch