[MySQL]Some nested query stuff

camelCase

The Case of the Mysterious Camel.
Reaction score
362
I have two tables:
+ server
+ users

Table 'server' has some info. like whether users are allowed to log in (allow_login).
Table 'users' just has some info. about each user, including their username and password.

I've never used nested queries (I think you call them that) because I never saw the use for them until now.
I can't think of any way to do a few things unless I run two queries.
Is there a way to do the following using just one query?

#1:
If query A returns only one row, run query B (can be a select/update statement on a different table)

#2:
If query A returns no results, run query B (can be a select/update statement on a different table)

#3:
If query A returns a certain value, don't run query B
Like, say, if 'allow_login' is "false" in table 'server', all attempts to log in will fail.

I'm kinda' playing around with C#, MySQL connector/.NET and prepared statements =x
 

Ghan

Administrator - Servers are fun
Staff member
Reaction score
888
All of this should be handled in the code you're writing. The database is meant purely to return information, not to act as part of the control structures in your code. If statements should be done purely in code and then each time you need to access or change data in the database you use the code's proper SQL access statements to do that.

Nested queries are queries within queries. For example, in a vBulletin database, you might want to find posts by users in a given usergroup, which could possibly be accomplished like this:

SELECT * FROM post WHERE userid IN (SELECT userid FROM user WHERE usergroupid = 1)
 

camelCase

The Case of the Mysterious Camel.
Reaction score
362
Ahh..
I always thought I should be letting MySQL do *all* the data-handling =x

Thanks.
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Staff online

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top