Diferent results on SELECT query
See original GitHub issueI have a table “users” whit this rows:
user_id user_name 1 Jhon 2 Paul
And other table “tests” with this rows:
test_id created_by_user_id modified_by_user_id 1 1 2
at psql shell, I send the following query:
SELECT test_id, created.user_name, modified.user_name FROM tests LEFT JOIN users as created ON tests.created_by_user_id = created.user_id LEFT JOIN users as modified ON tests.modified_by_user_id = modified.user_id
as expected, I have thr following result:
test_id created modified 1 Jhon Paul
but using pg-node whit the same query as:
const result = await client.query('SELECT test_id, created.user_name, modified.user_name FROM tests LEFT JOIN users as created ON tests.created_by_user_id = created.user_id LEFT JOIN users as modified ON tests.modified_by_user_id = modified.user_id')
in result.rows I have this:
test_id created modified 1 Jhon Jhon
Issue Analytics
- State:
- Created 4 years ago
- Comments:5
Top Results From Across the Web
Same query producing different results - sql - Stack Overflow
I see only one query. I would point out that underlying data can change, and so the same query can generate different results....
Read more >How to handle an equivalent query producing different results ...
If you have an “equivalent query” producing different results, then it is not an equivalent query. Ideally, you would break the query down...
Read more >About the same SQL Server query get different result in two PCs
Hello guys , there is a problem when I run my SQL query. When I run the follow query in my PC ,....
Read more >Same query, same data, different results between S... - 89917
I am running the following query on the same data (same tables, and the same number of records on those - 89917.
Read more >Why am I getting different results from a query vs. a view
I need to create two views (because MySQL won't let me have a subquery in a view). My first query sets up the...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Hi, that’s happening because you haven’t used aliases in your return fields. This is what the query returns (both in psql and when it’s run by node-pg):
When node-pg parses that row, it finds two columns both named
user_name
, and because those get assigned to an object, the second one replaces the first one. So what you get inresult.rows
is actually:You could either:
created.user_name AS created_by, modified.user_name AS modified_by
):rowMode: 'array'
):Great to hear, you’re welcome.