Jump to content

updating table query


Go to solution Solved by Barand,

Recommended Posts

Ok i have a table with headings

username   useremail   randomnumber   neptune   morethen5

 

 

What im trying to do is if a username has more than 5 records where neptune isnt null update  the morethan5 column for all username with yes

 

this is the query i have


update ballot
set morethan5 = yes
where username in
(
  select * from
  (
    select neptune
    from  ballot
    group by username
    having count(1) > 5
  ) x
)

i got first of all an error saying yes  column didnt exist so i created a new column called yes  and it isnt updating any records

Link to comment
https://forums.phpfreaks.com/topic/300601-updating-table-query/
Share on other sites

that fixed the error  but its still not updating the column  here is an example of  the table

 

 

 

 pie [email protected] 46276 \N  
taz [email protected] 49042 \N  
taz [email protected] 49042 \N  
wicked [email protected] 41494 \N  
wicked [email protected] 41494 \N  
nnn [email protected] 38915 neptune  
nnn [email protected] 38808 neptune  
nnn [email protected] 38915 neptune  
nnn [email protected] 38808 neptune  
nnn [email protected] 38915 neptune  
nnn [email protected] 38808 neptune  

what im trying to do is count how many  for each username that has  a non null  in the column neptune and if ithe same player has more then 5 Non Null values to mark the morethan5 column with yes

Edited by Justafriend
  • Solution

try

UPDATE ballot
INNER JOIN 
    (
    SELECT username
    , COUNT(neptune) as ncount
    FROM ballot
    GROUP BY username
    HAVING ncount > 5
    ) n USING (username)
SET morethan5 = 'yes'

However, it is bad practice to store derived data like that in a db table.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.