Using the code below:
SELECT invoices.amount, customers.name, customers.image_url, customers.email, invoices.id
FROM invoices
JOIN customers ON invoices.customer_id = customers.id
ORDER BY invoices.date DESC
LIMIT 5
the result I get is:
{
id: '76d65c26-f784-44a2-ac19-586678f7c2f2',
name: 'Michael Novotny',
email: 'michael@novotny.com',
image_url: '/customers/michael-novotny.png',
},
duplicated 5 times as opposed to the most recent descending order of unique objects from my placeholder data:
{
id: 'd6e15727-9fe1-4961-8c5b-ea44a9bd81aa',
name: 'Evil Rabbit',
email: 'evil@rabbit.com',
image_url: '/customers/evil-rabbit.png',
},
{
id: '3958dc9e-712f-4377-85e9-fec4b6a6442a',
name: 'Delba de Oliveira',
email: 'delba@oliveira.com',
image_url: '/customers/delba-de-oliveira.png',
},
{
id: '3958dc9e-742f-4377-85e9-fec4b6a6442a',
name: 'Lee Robinson',
email: 'lee@robinson.com',
image_url: '/customers/lee-robinson.png',
},
{
id: '76d65c26-f784-44a2-ac19-586678f7c2f2',
name: 'Michael Novotny',
email: 'michael@novotny.com',
image_url: '/customers/michael-novotny.png',
},
{
id: 'CC27C14A-0ACF-4F4A-A6C9-D45682C144B9',
name: 'Amy Burns',
email: 'amy@burns.com',
image_url: '/customers/amy-burns.png',
},
Can some one point out where I have gone wrong, cause after several iterations and going through documentation, I can’t see why am not getting the latter result of 5 different objects instead of the one object duplicated 5 times.
Below is a screenshot of the code in the query and the results before is only a duplicate as opposed to the seeded data that has more values. database query
Chapter 7 https://nextjs.org/learn/dashboard-app/fetching-data
I have gone over the sql documentation and reviewed the code and I can’t figure out why I am having an issue and hoping someone who also had one may have an alternative as this is part of the tutorial that is not recommended to be used in production as it is an unstable version.
Even seeding the data was a point of topic in other various forums in regards to web developers trying to get it right and master this latest way of programming in NextJS
Update: After more troubleshooting, I used the code below:
SELECT invoices.amount, customers.name, customers.image_url, customers.email, invoices.id
FROM invoices
JOIN customers ON invoices.customer_id = customers.id
LIMIT 5
And I manage to pull up:
{
id: 'd6e15727-9fe1-4961-8c5b-ea44a9bd81aa',
name: 'Evil Rabbit',
email: 'evil@rabbit.com',
image_url: '/customers/evil-rabbit.png',
},
{
id: '3958dc9e-712f-4377-85e9-fec4b6a6442a',
name: 'Delba de Oliveira',
email: 'delba@oliveira.com',
image_url: '/customers/delba-de-oliveira.png',
},
{
id: '3958dc9e-742f-4377-85e9-fec4b6a6442a',
name: 'Lee Robinson',
email: 'lee@robinson.com',
image_url: '/customers/lee-robinson.png',
},
{
id: '76d65c26-f784-44a2-ac19-586678f7c2f2',
name: 'Michael Novotny',
email: 'michael@novotny.com',
image_url: '/customers/michael-novotny.png',
},
{
id: 'CC27C14A-0ACF-4F4A-A6C9-D45682C144B9',
name: 'Amy Burns',
email: 'amy@burns.com',
image_url: '/customers/amy-burns.png',
},
However they aren’t in descending order by the invoice date:
ORDER BY invoices.date DESC
If you scroll to the top, you will see the “ORDER BY” line of code causes only one object to be brought up 5 times when run on the postgresql dashboard.
I am now trying to figure out how to to get the descending order of the 5 unique objects I get with the code that doesn’t include the “ORDER BY” line… any outside perspective input are insights I would value in helping me crack this, please? Am still trouble shooting and going through documentation on my end as well.