Raised This Month: $51 Target: $400
 12% 

Check Two Tables Mysql


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
pepe_thugs
Senior Member
Join Date: Aug 2010
Location: Portugal , Braga
Old 12-25-2015 , 11:55   Check Two Tables Mysql
Reply With Quote #1

Hello guys
It is possible to check two tables in the database with the same query?
If so can you help me?

PHP Code:
FormatEx(Querysizeof(Query), "SELECT bid FROM %s_bans AND sb_bansdisconect WHERE ((type = 0 AND authid REGEXP '^STEAM_[0-9]:%s$') OR (type = 1 AND ip = '%s')) AND (length = '0' OR ends > UNIX_TIMESTAMP()) AND RemoveType IS NULL"DatabasePrefixauth[8], ip); 
EDIT:

This should Work?

PHP Code:
FormatEx(Querysizeof(Query), "SELECT bid FROM %s_bans WHERE ((type = 0 AND authid REGEXP '^STEAM_[0-9]:%s$') OR (type = 1 AND ip = '%s')) AND (length = '0' OR ends > UNIX_TIMESTAMP()) AND RemoveType IS NULL UNION SELECT bid FROM %s_bansdisconect WHERE ((type = 0 AND authid REGEXP '^STEAM_[0-9]:%s$') OR (type = 1 AND ip = '%s')) AND (length = '0' OR ends > UNIX_TIMESTAMP()) AND RemoveType IS NULL"DatabasePrefixauth[8], ipDatabasePrefixauth[8], ip); 

Last edited by pepe_thugs; 12-25-2015 at 15:53.
pepe_thugs is offline
Neuro Toxin
Veteran Member
Join Date: Oct 2013
Location: { closing the void; }
Old 12-25-2015 , 18:10   Re: Check Two Tables Mysql
Reply With Quote #2

http://dev.mysql.com/doc/refman/5.7/en/join.html
__________________
Neuro Toxin is offline
pepe_thugs
Senior Member
Join Date: Aug 2010
Location: Portugal , Braga
Old 12-26-2015 , 08:00   Re: Check Two Tables Mysql
Reply With Quote #3

Quote:
Originally Posted by Neuro Toxin View Post
I will realized?
It's simple just do this:



PHP Code:
FormatEx(Querysizeof(Query), "SELECT bid FROM %s_bans, sb_bansdisconect WHERE ((type = 0 AND authid REGEXP '^STEAM_[0-9]:%s$') OR (type = 1 AND ip = '%s')) AND (length = '0' OR ends > UNIX_TIMESTAMP()) AND RemoveType IS NULL"DatabasePrefixauth[8], ip); 

The tables are completely equal with the same structure.
I just wanted to separate some bans to not appear in the same database.
I'll now create different commands to ban for both database and separate these bans.
pepe_thugs is offline
pepe_thugs
Senior Member
Join Date: Aug 2010
Location: Portugal , Braga
Old 12-27-2015 , 19:35   Re: Check Two Tables Mysql
Reply With Quote #4

Please someone can help please?
Sorry for bump
pepe_thugs is offline
ThatOneGuy
Veteran Member
Join Date: Jul 2012
Location: Oregon, USA
Old 01-01-2016 , 16:06   Re: Check Two Tables Mysql
Reply With Quote #5

Neuro toxin already explained what you need. Use SQL join to join two tables on an identifier in a select statement. Here is a diagram to help you pick the correct kind of join: http://www.codeproject.com/KB/databa...JOINS_orig.jpg

If the columns are the exact same, you will need to include which tbl it is from when you specify a column. e.g.
sb_bansdisconect.authid
__________________
ThatOneGuy is offline
pepe_thugs
Senior Member
Join Date: Aug 2010
Location: Portugal , Braga
Old 01-02-2016 , 14:53   Re: Check Two Tables Mysql
Reply With Quote #6

Quote:
Originally Posted by ThatOneGuy View Post
Neuro toxin already explained what you need. Use SQL join to join two tables on an identifier in a select statement. Here is a diagram to help you pick the correct kind of join: http://www.codeproject.com/KB/databa...JOINS_orig.jpg

If the columns are the exact same, you will need to include which tbl it is from when you specify a column. e.g.
sb_bansdisconect.authid
Like This:

PHP Code:
FormatEx(Querysizeof(Query), "SELECT bid FROM sb_bans AS bans INNER JOIN sb_bansdisconect AS bansdisc ON bansdisc.authid = bans.authid WHERE ((bans.type = 0 AND bans.authid REGEXP '^STEAM_[0-9]:%s$' AND bansdisc.type = 0 AND bansdisc.authid REGEXP '^STEAM_[0-9]:%s$') OR (bans.type = 1 AND bans.ip = '%s' AND bansdisc.type = 1 AND bansdisc.ip = '%s')) AND (bans.length = '0' OR bans.ends > UNIX_TIMESTAMP() AND bansdisc.length = '0' OR bansdisc.ends > UNIX_TIMESTAMP()) AND bans.RemoveType IS NULL AND bansdisc.RemoveType IS NULL"auth[8], auth[8], ipip
This should Work?
pepe_thugs is offline
ThatOneGuy
Veteran Member
Join Date: Jul 2012
Location: Oregon, USA
Old 01-02-2016 , 15:58   Re: Check Two Tables Mysql
Reply With Quote #7

Look ok...try running the query first in your phpmyadmin, but it looks right (be sure to replace the SM formatting with some values in the database for testing). Also, if the DBs are near identical, any field that are going to contain the same value in both only need to be checked in one of them. e.g. the join is on authid, therefor just check once and no need to check both.
__________________
ThatOneGuy is offline
pepe_thugs
Senior Member
Join Date: Aug 2010
Location: Portugal , Braga
Old 01-02-2016 , 16:51   Re: Check Two Tables Mysql
Reply With Quote #8

Quote:
Originally Posted by ThatOneGuy View Post
Look ok...try running the query first in your phpmyadmin, but it looks right (be sure to replace the SM formatting with some values in the database for testing). Also, if the DBs are near identical, any field that are going to contain the same value in both only need to be checked in one of them. e.g. the join is on authid, therefor just check once and no need to check both.
I try to run this in phpmyadmin :

PHP Code:
SELECT FROM sb_bans AS bans INNER JOIN sb_bansdisconect AS bansdisc ON bansdisc.authid bans.authid WHERE ((bans.type AND bans.authid 'STEAM_1:1:xxxxx' AND bansdisc.type AND bansdisc.authid 'STEAM_1:1:xxxxx' ) OR (bans.type AND bans.ip '%s' AND bansdisc.type AND bansdisc.ip '%s')) AND (bans.length '0' OR bans.ends UNIX_TIMESTAMP() AND bansdisc.length '0' OR bansdisc.ends UNIX_TIMESTAMP()) AND bans.RemoveType IS NULL AND bansdisc.RemoveType IS NULL 
I insert one steam id I have in the database and did not return me any value says that there is none.
pepe_thugs is offline
DarkDeviL
SourceMod Moderator
Join Date: Apr 2012
Old 01-03-2016 , 07:01   Re: Check Two Tables Mysql
Reply With Quote #9

Quote:
Originally Posted by pepe_thugs View Post
I insert one steam id I have in the database and did not return me any value says that there is none.
Well, you could try elaborating on what exactly you are trying to do, and what you expect the results to be.

1. Provide us a full table structure of both SQL tables you are selecting from.

2. Provide the names of fields from each of them that you want to receive.

3. Provide a example data set of how things looks in both tables.

4. What do you want to do when table A has items, but table B doesn't? (or the other way around)?

.. etc etc. The more details you give about what you are trying to do / what you expect, the better others outside can help you.

As you don't really provide any details except saying you want to check two tables at once; you are most likely to get completely ignored. "Can you help me?"-like questions doesn't get you help. Details about the problem does!
__________________
Mostly known as "DarkDeviL".

Dropbox FastDL: Public folder will no longer work after March 15, 2017!
For more info, see the [SRCDS Thread], or the [HLDS Thread].
DarkDeviL is offline
pepe_thugs
Senior Member
Join Date: Aug 2010
Location: Portugal , Braga
Old 01-03-2016 , 08:44   Re: Check Two Tables Mysql
Reply With Quote #10

I'm trying to change the query's SourceBans to check two tables.
The original query is this:

PHP Code:
FormatEx(Querysizeof(Query), "SELECT bid FROM %s_bans  WHERE ((type = 0 AND authid REGEXP '^STEAM_[0-9]:%s$') OR (type = 1 AND ip = '%s')) AND (length = '0' OR ends > UNIX_TIMESTAMP()) AND RemoveType IS NULL"DatabasePrefixauth[8], ip
Now I created another database to separate some bans the databases have the same structure (structure attached).

Now I wanted to create a query that checks first if there was any record in the database "sb_bans" and if not, check the database "sb_bansdisconect"
And I do not know if I can do everything in the same query.
I'll attach the plugin edited but that did not work I created a command to separate the bans for another database (line 174).
The command worked well, but did not work the query to see if the player is banned.
Attached Thumbnails
Click image for larger version

Name:	Structure DataBase.png
Views:	184
Size:	56.0 KB
ID:	150924  
Attached Files
File Type: sp Get Plugin or Get Source (sourcebans.sp - 121 views - 80.4 KB)

Last edited by pepe_thugs; 01-03-2016 at 08:47.
pepe_thugs is offline
Reply



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 10:21.


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