Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Select Non-repeating Planet/Satellite Combinations
create table devstronomy.temp_l_satellite like devstronomy.l_satellite;
alter table devstronomy.temp_l_satellite add primary key (id);
alter table devstronomy.temp_l_satellite add column ins_ts timestamp default current_timestamp not null;
insert ignore into devstronomy.temp_l_satellite
select ls.*, current_timestamp
from devstronomy.l_satellite ls
where planet_id = (select
from devstronomy.l_planet lp
order by rand()
limit 1)
and not exists (select 1
from devstronomy.temp_l_satellite tls
where =
limit 1
order by rand()
limit 1;
select *
from devstronomy.temp_l_satellite
order by ins_ts desc
limit 1;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment