T
T
taurus902015-04-10 15:59:14
MySQL
taurus90, 2015-04-10 15:59:14

MySQL JOIN expression?

Good afternoon. The following working SQL statement is currently being used:

SELECT T.*, I.SUBDIR, I.FILE_NAME, ep.VALUE AS AV 
FROM (SELECT p.ID, p.ACTIVE, p.NAME, p.CODE, p.DETAIL_PICTURE, p.PREVIEW_TEXT, p.PREVIEW_PICTURE, p.DETAIL_TEXT, p.IBLOCK_SECTION_ID, e.PRICE 
FROM b_iblock_element p, b_catalog_price e WHERE e.PRODUCT_ID = p.ID AND p.IBLOCK_ID = 2 and p.ACTIVE = "Y" and e.CATALOG_GROUP_ID = 1) T 
LEFT JOIN b_file I ON T.DETAIL_PICTURE = I.ID 
LEFT JOIN b_iblock_element_property ep ON ep.IBLOCK_ELEMENT_ID = T.ID AND ep.IBLOCK_PROPERTY_ID = 2242 WHERE 1';

Unfortunately, I have little understanding of the meaning of this expression, but I know the basics of SQL. What does "WHERE 1" mean at the end?
Main question. This request returns an object with a description of the product in the online store. The price (PRICE) is requested from the table b_catalog_price , where the desired product ID and column CATALOG_GROUP_ID is 1.
How can I additionally include the value of the PRICE column for CATALOG_GROUP_ID = 2 in the result? I would be grateful for clarification ....
And it would also be nice to have a link to a clear description of JOIN ... Thank you

Answer the question

In order to leave comments, you need to log in

3 answer(s)
T
taurus90, 2015-04-10
@taurus90

I managed to solve the problem by adding the following parameter to the first line of SELECT:
And at the very end, removing WHERE 1, add JOIN:
Thanks who helped!

R
retvizan, 2015-04-10
@retvizan

Dock or, if in Russian - www.cyberforum.ru/mysql/thread782307.html
WHERE 1 this is visible from the cms piece.

D
Dmitry Bay, 2015-04-10
@kawabanga

"where 1" is equal to "where true", which means always true, this is probably necessary to compose the next filtering parameters. For example, we have a code that filters according to the following principle:
if ( condition) then add "and expression from the condition" to the where block. Without where 1 there will be a syntax error.
On the main question, if you need to add two values, then perhaps like this
"and e.CATALOG_GROUP_ID in (1,2)" or like this "and (e.CATALOG_GROUP_ID=1 or e.CATALOG_GROUP_ID=2)"
Where the syntax is most clearly explained ? in reference of course!
www.mysql.ru/docs/man/JOIN.html

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question