How can i get the number of elements ignoring the subtable elements?

I want to get the orders I have, but when I do the select I have differents rows for every item, but I don’t know how to get orders ignoring items

ORDERS
ID 
1
2 
3
ORDER_PRODUCT
ID ORDER_ID PRODUCT_ID
1  1        1    
1  1        2
1  2        3
1  3        4
SELECT ORDER_PRODUCT.* FROM ORDER_PRODUCT INNER JOIN ORDERS ON ORDERS.ID = ORDER_PRODUCT.ORDER_ID LIMIT 2;

I expect to get the 2 orders info, but I recieve the 2 first items, how can I get the 2 orders?

What I recieve:

ID ORDER_ID PRODUCT_ID
1  1        1
1  1        2

What I expect to recieve:

ID ORDER_ID PRODUCT_ID
1  1        1
1  1        2
1  2        3

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

If I did understand what you are trying to approach, you are trying to limit the inner join elements, so instead of limiting the whole query you should do something like that to limit only the inner join:

SELECT op.ID FROM ORDER_PRODUCT op 
INNER JOIN (SELECT * FROM ORDERS LIMIT 2) as o ON o.ID = op.ORDER_ID;

Also I supose you also want to add conditions in the inner join query, just add them before the limit.

If it is not what you are trying to achieve, let me know.


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x