I have table like below :
Application_Number Id_Number1 Name
1 123 John
2 456 Alan
3 789 Charlie
4 111 Patrick
5 222 Robert
Then i would like to update record in one of rows become like this :
Application_Number Id_Number1 Name
1 123 Alias 1
2 456 Alias 2
3 789 Alias 3
4 111 Alias 4
5 222 Alias 5
if i have more than one million record do i need update syntax or any another way? I'm using SQL2008
Thanks
Select Application_Number
,Id_Number1
,'Alias' + CAST( ROW_NUMBER()
OVER (ORDER BY Application_Number) AS Varchar) AS Name
FROM Table Name
Related
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.
Note : I cannot change Table structure
These are the three tables- user,user_field_type and user_field_value which needs to be joined and produce the result shown below
user
User_code User_id
-----------------
test11 000_1
test12 000_2
test13 000_3
test14 000_5
user_field_type
field_name field_id
----------------------
Name 100_1
Age 100_2
Class 100_3
Roll 100_4
User_field_value
user_id field_id field_value
-------------------------------------
000_1 100_1 Tom
000_1 100_2 6
000_1 100_3 2
000_1 100_4 1
000_2 100_1 Dick
000_2 100_2 6
000_2 100_3 2
000_2 100_4 2
000_3 100_1 Harry
000_3 100_2 6
000_3 100_3 2
000_3 100_4 3
Result Needed:
user_id user_code Name Age Class Roll
------------------------------------------------
000_1 test11 Tom 6 2 1
000_2 test12 Dick 6 2 2
000_3 test13 Harry 6 2 3
I tried Group concat which doesn't produce desired results and i'm afraid of hard coding columns as it will require changes everytime we add a new user field type
From a table which has 2 columns ID and Flag
ID Flag
111 2
222 2
333 2
444 2
333 5
111 5
I want to select all id which have 2 flag but not 5
expected answer
222
444
I tried below but that won't work.
SELECT * from table
where flag in ('2')
and flag not in ('5')
SELECT id
FROM source
GROUP BY id
HAVING SUM(flag=2)
AND !SUM(flag=5)
I use MySql and I have some problems with it ^^
Let's say I have two tables which will be "FirstTable" and "SecondTable"
First table (ID isn't the primary key)
ID IdCust Ref
1 300 123
1 300 124
2 302 345
And the second (ID isn't the primary key)
ID Ref Code Price
1 123 A 10
1 123 Y 15
2 124 A 14
3 345 C 18
[EDIT] The column "Stock" in the final result is equals to "ID" in the second table
The column "Stock", "Code" and "Price" can have x values, so I don't know it, in advance...
I make some research in stackoverflow, but I only find post where people use "count(case when ..."
Like this one : MySQL pivot row into dynamic number of columns
For my problem, I cannot use it, because i can't know in advance the value of reference
I'm trying to produce the following output:
The result I want
[EDIT] Result in TXT
ID IdCust Ref StockA Code1 Price1 StockB Code2 Price2
1 300 123 1 A 10 1 Y 15
1 300 124 2 A 14
2 300 345 3 C 18
I have a following data below:
Table:
Name Number
Sam 1
Sam 2
Sam 3
John 4
Lani 5
Mera 6
Now I want as a result like this format below
Result:
Name Number
Sam 1,2,3
John 4
Lani 5
Mera 6
How can I possibly do this? What I must going to use?
You can do this with group_concat():
select name, group_concat(number order by number) as numbers
from t
group by name;