Raised This Month: $18 Target: $400
 4% 

MySQL Query Help


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Weetabix
Member
Join Date: Feb 2017
Location: United Kingdom
Old 06-03-2020 , 14:40   MySQL Query Help
Reply With Quote #1

Hello brothers,

Just a little question about mysql and forgive me if this is the wrong place to ask this.
I use the follwing query to inset/update a value if the steamid is already present in the table. (SteamID is primary)

PHP Code:
INSERT INTO Table (SteamIDCreditsVALUES ('123''123'ON DUPLICATE KEY UPDATE Credits VALUES(Credits
However, I want to check if both steamid and another column exist together and then update the value as before. For example if Steami(123) and Credits(123) are present in the same row then update another value within that row. I just have no idea really on how to do it.

Thank you
Weetabix is offline
DJ Tsunami
DJ Post Spammer
Join Date: Feb 2008
Old 06-03-2020 , 14:56   Re: MySQL Query Help
Reply With Quote #2

You can create a primary key on multiple fields:

PHP Code:
CREATE TABLE Table (
    
SteamID ...,
    
Credits ...,
    
PRIMARY KEY (SteamIDCredits)

Or just create a unique index on both fields:

PHP Code:
CREATE UNIQUE INDEX Table_SteamID_Credits_idx
ON Table 
(SteamIDCredits
__________________

Last edited by DJ Tsunami; 06-03-2020 at 14:59.
DJ Tsunami is offline
Weetabix
Member
Join Date: Feb 2017
Location: United Kingdom
Old 06-03-2020 , 15:08   Re: MySQL Query Help
Reply With Quote #3

Quote:
Originally Posted by DJ Tsunami View Post
You can create a primary key on multiple fields:

PHP Code:
CREATE TABLE Table (
    
SteamID ...,
    
Credits ...,
    
PRIMARY KEY (SteamIDCredits)

Or just create a unique index on both fields:

PHP Code:
CREATE UNIQUE INDEX Table_SteamID_Credits_idx
ON Table 
(SteamIDCredits
Thank you DJ!
Weetabix is offline
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 01:31.


Powered by vBulletin®
Copyright ©2000 - 2020, vBulletin Solutions, Inc.
Theme made by Freecode