Pregunta

I made a shopping cart web application for a stores. If a customer log into the system, They are adding some items to there shopping cart. In my case, I store that all cart items in table named, ShoppingCart. I have 2 tables named, Customer and ShoppingCart. ShoppingCart primary key is userName. userName is a attribute of Customer table. I need to get all the ShoppingCart entries where userName.

SELECT o FROM ShoppingCart o, Customer c WHERE c.userName = :id

id is the primary key of ShoppingCart. I failed to get correct result from this query. How can I do it?

Thanks in Advance.

¿Fue útil?

Solución

You can try the below query. In your query, you haven't added which column should be joined to fetch exact results for the given id.

SELECT o FROM ShoppingCart o, Customer c WHERE c.userName = o.userName AND o.userName = :id

Also, you can try adding relationships one-to-many as each customer can have one or more than that order items.

SELECT c FROM Customer c JOIN c.orders o WHERE c.userName = :id

Here, orders is the collection of orders for particular customer. Then from Customer, you can get its orders.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top