Skip to content

Instantly share code, notes, and snippets.

@g105b
Created February 17, 2021 10:09
Show Gist options
  • Save g105b/901736764b6940c0eff053928c941706 to your computer and use it in GitHub Desktop.
Save g105b/901736764b6940c0eff053928c941706 to your computer and use it in GitHub Desktop.
Converting a MySQL question mark parameter to a named parameter for reuse in the same query
select
(@param1 := ?),
value,
timestamp,
Field.name,
Site.id
from
Field_Value
inner join
Site_Field
on
id_Site_Field = Site_Field.id
inner join
Site
on
id_Site = Site.id
where
(@param1 is null
or Site.id = @param1)
order by
id desc
limit 10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment