'How to JOIN tables without generating null for column id
I'm using Supabase and when a user calls endpoint /crypto_signals I want to do a SQL query first where I join notification table columns to crypto_signals based on crypto_signals id to notifications coin_id
crypto_signals table
id coin
1 BTC
2 ETH
3 SOL
notifications table
id id_coin user_id
1 1 1
2 3 2
Expected response when user 1 make request to /crypto_signal
id coin coin_id id_notification
1 BTC 1 1
2 ETH null null
3 SOL null null
Current code so far
select *
from crypto_signals
left join notifications
on crypto_signals.id = notifications.coin_id
Output
id coin coin_id user_id
3 ETH null null
4 BTC 1 1
null Sol null null
my crypto_signal id is lost and instead using the notifications id
EDIT SOLVED
select crypto_signals.*,
notifications.id as notification_id,
notifications.coin_id
from crypto_signals
left join notifications
on crypto_signals.id = notifications.coin_id
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
