JSP MYSQL Hide Same Number and show letter - mysql

I am a newbie still learning jsp and mysql.
I have a database with following table fields:
id no letter content
1 1 book
2 2 pen
3 3 a apple
4 3 b mango
5 3 c banana
6 4 car
I need somebody help me, how can I do a query in jsp with mysql so the result will be like this?
No Content
1. book
2. pen
3. a apple
b mango
c banana
4. car

Related

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.

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!

How to avoid repeated content in mysql tables?

I have two tables and they have "Many to Many" relation. The problem is in mirror table where I have 2 more fields "name" and "status". For name field values will be "Youtube, DailyMotion and Mp4Upload" and for status values will be "Subbed, Dubbed and Raw". For every link I am placing these value and the duplication occurs.
Demo:
mirror table
id name link status
1 Mp4Upload Some link 1 Subbed
2 Mp4Upload Some link 2 Subbed
3 Mp4Upload Some link 3 Subbed
4 Mp4Upload Some link 4 Raw
5 Mp4Upload Some link 5 Raw
6 YouTube Some link 6 Dubbed
7 YouTube Some link 7 Dubbed
Is there any way I can avoid repeated content by some relation? Like consider the above relation. One episode have many mirrors and many mirrors belong to one episode. We solved this using a third table pivot table episode_mirror.
Other Tables are
episode table
id name
1 First Episode
2 Second Episode
3 Third Episode
4 Fourth Episode
episode_mirror (pivot table)
id episode_id mirror_id
1 1 1
2 1 2
3 1 3
I hope this make sense to every one and thanks a lot.
Create a table for both name and status.
status_id | status
1 | subbed
2 | dubbed
3 | raw
name_id | name
1 | mp4upload
2 | youtube
3 | dailymotion
Then in your first table, use ids corresponding to those new tables
id name_id link status_id
1 1 Some link 1 1
2 1 Some link 2 1
3 1 Some link 3 1
4 1 Some link 4 3
5 1 Some link 5 3
6 2 Some link 6 2
7 2 Some link 7 2
This will save you a large amount of space and repetition from repeating the strings.

SQLite COUNT and selecting from multiple tables

Consider the database (made up for example):
Table 'owner'
id name
1 john
2 andrew
3 peter
Table 'duck'
id name ownerID
1 duck1 1
2 duck2 1
3 duck3 1
4 duck4 2
5 duck5 2
6 duck6 3
7 duck7 3
8 duck8 1
9 duck9 3
10 duck10 3
11 duck11 1
12 duck12 2
Table 'food'
id name type duckID
1 beef meat 4
2 grass veg 8
3 lemon fruit 5
4 apple fruit 3
5 pizza snack 7
I wish to write some SQL that for each OWNER, COUNT the number of ducks which eat some kind of food. For example for owner John, there would be 2 ducks (ducks 3 and 8).
So far I am writing this code:
select owner.name, count(duck.ownerID)
from duck, food, owner
where duck.id == food.duckID
and duck.ownerID == owner.id;
I am getting the result:
Peter | 5
Any suggestions are appreciated.
This is done with an group by clause:
select owner.name, food.name, count(duck.id)
from duck, food, owner
where duck.id == food.duckID
and duck.ownerID == owner.id
group by owner.name, food.name;
This query gives you one row for each combination of owner name and food name with the number of the owner's ducks eating this food.

Group by using local storage in HTML5

I am creating my first mobile application using HTML5 and JqueryMobile. Storing all datas in localstorage. Anyone can suggest me the easy way to retrieve grouped data count from following resultset,
1 mango
2 orange
3 mango
4 apple
5 mango
6 apple
7 orange
8 orange
9 apple
10 mango
Expected result
mango 4
orange 3
apple 3
you can do the same using query lik
SELECT Fruit_Name, COUNT(*) as "Fruit Count"
FROM Fruits
GROUP BY Fruit_Name;
Selecting data and rendering in HTML5 is explained here.