making a sentence recursive in sql - mysql

I have a table:
id owner ex_id
1 jack -
2 joe -
3 charlie 1
4 bill 3
5 helen 2
6 jack 5
7 anna 4
8 Kurt 7
It is possible to have in a select sentence (not a program, just sql) something like "get all the ex_id´s from id 7":
id 7: anna, bill, charlie, jack
(7 point to 4, 4 point to 3, 3 point to 1, 1 dont have property so it ends)
TIA

It is not possible to perform such a hierarchical query using pure SQL in MySQL, sorry to say.
Oracle can do it. http://docs.oracle.com/cd/B19306_01/server.102/b14200/queries003.htm But that's not what you asked.

Related

MySQL Split String Into Separate Rows Using RegEx

I have some text data in a column similar to this in MySQL 8.0.30:
Id
Weights
1
James Brown 10-10 John Doe 12-9 Sue Smith 9-9 Dick Turpin 9-12
2
Some Other 9-1 Example Name 8-13
There could be any number of name/weight combinations in the column. I want to pull these out into separate rows like so
Id
Weights
1
James Brown 10-10
1
John Doe 12-9
1
Sue Smith 9-9
1
Dick Turpin 9-12
2
Some Other 9-1
2
Example Name 8-13
I've tried using the regex_substr to no avail as I could only get it to return a single match. How could I go about doing this?

Gaming Database Query for multiple players

I want to have a SQL result look like this (match result query):
ID Arena Winner Loser Winner_score Loser_score
-----------------------------------------------------------------
1 1 Johnny Mark 16 8
2 2 Andrew Luke 16 7
Here are my tables (simplified)
Player_tbl
ID Player
-------------
1 Johnny
2 Mark
3 Andrew
4 Luke
Match_tbl
ID Match Arena
----------------------
1 Match 1 1
2 Match 2 2
Match_results_tbl
ID Match player_id player_score
-----------------------------------------
1 Match 1 1 16
2 Match 1 2 8
1 Match 2 3 16
2 Match 2 4 7
I am wondering how to structure my query to have the desired result.
Ok, I figured out my own issue. 1st, the match_results must be put in a table with a different structure, and 2nd, the inner sql query needed to be adjusted to pull from the proper database tables.

Moving consecutive results to different columns

I have the following table:
Transaction Id
Authorizer
1
john
1
robert
2
Jane
2
Paul
And the result table I need is like this:
Transaction Id
Authorizer_1
Authorizer_2
1
john
Robert
2
Jane
Paul
How can i make this in Teradata SQL assistant?
Thanks in advance!

MySQL query - need assistance creating this query

I need some direction on how to create this MySQL query.
I have a table that looks like this.
id group name value
1 1 user mike
2 1 setting 1
3 2 user joe
4 2 setting 2
5 3 user jill
6 3 setting 1
7 4 user mark
8 4 setting 1
9 4 other 22
I would like to format the query to group users that have identical settings (IE mike and jill would be grouped in this example, not mark because of "other")
At the end of the day I am trying to consolidate and make the table look like this. If I can figure out the query to properly group them ,I will use PHP to combine the values and save it back to the DB.
id group name value
1 1 user mike OR jill
2 1 setting 1
3 2 user joe
4 2 setting 2
7 4 user mark
8 4 setting 1
9 4 other 22
Thank you!

I need sql query for getting the Required format

i am having table Category with the columns like
id(AutoIncrement),Parent_id,Level,Name
initially for level 1 datas has Parent_id is 0. autoincrement id will be Parent_id for next levels .my table table table datas will bw like this
id Parent_id Level Name
1 0 1 Indian
2 0 1 International
3 0 1 Nri
4 1 2 BC
5 2 2 Christian
6 2 2 Muslim
7 4 3 MBC-1
8 7 4 OBC-2
9 1 2 FC
i want to show records in this format (its like a tree view)
id Parent_id Level Name
1 0 1 Indian
4 1 2 BC
7 4 3 MBC-1
8 7 4 OBC-2
9 1 2 FC
5 2 2 Christian
6 2 2 Muslim
2 0 1 International
3 0 1 Nri
4 1 2 BC
Can any one should help me to get this arrangement of datas using sql Query?
If it does not have a set number of branches you likely want to loop over a query in your app or write an SP to obtain all nodes. Some good reading here:
http://mikehillyer.com/articles/managing-hierarchical-data-in-mysql/