SQL Select i dunno what exactly mean - mysql

i have sql table like this
pets playstart endstart
cat 12:10 12:50
dog 13:10 13:50
lion 14:10 14:50
if i select 13:35
result dog
how create sql query for this command?

In answer to the question. A select statement is a statement that aims at retrieving some data. SQL was invented to be a human readable way of interacting with databases. As such you can almost phrase your query as a question.
In this case your question would be "What pet would be played with at 13:35?".
Provided the table is guaranteed to have none-overlapping "playstart" and "playend" values this should work (I don't know what the name of your table is so I've used "yourtable" to represent that).
select pets from yourtable where playstart <='13:35' and playend >='13:35'

Please try this one, I hope this will works for you
select pets from pets where playstart >= '13:10' and endstart <= '13:50'

Related

How do I output the mutual results appearing in two queries?

I have made 2 simple queries which output the forename and surname of people based upon the value of a column "role" in a junction table they are associated with.
Lets say that the output is:
Kevin Baker
Julie Willis
Gregory Hilliard
Joe Swanson
Patrick Day
Bethany Row
for one of the query outputs and:
Kevin Baker
Michael Winter
Ellie Patterson
for the other.
I want to be able to make a query which outputs the values that appear in both of these tables i.e. I want it to output Kevin Baker in this case.
Is there a simple way to do this based upon the two queries I have already made?
I have managed to do it myself. I am not sure if it is the best method but it was simple and works.
I kept the first query the same and added
AND IN()
to the end of the WHERE statement.
I then pasted the second query into the IN statement and altered it to only SELECT the id of the related attributes in the outer query.
If you need an intersect just JOIN these queries:
Select Q1.Name FROM (QUERY1) Q1
JOIN
(QUERY2) Q2 On Query1.Name=Q2.Name

Use MySQL to Find Duplicates and Display on One Line

I'd like to use MySQL to find duplicates and then display those items as one, combined record. For example, I have two columns: Name and Fruit. A sampling of records might look like this:
Joe - Peaches
Faye - Bananas
Joe - Starfruit
Sam - Apples
I want to display this data as:
Joe - Peaches, Starfruit
Faye - Bananas
Sam - Apples
Is that possible? Could you help me with the MySQL query to start? I'm using VB.NET for my application. Thank you.
Use GROUP_CONCAT for that.
SELECT personName, GROUP_CONCAT(fruitName) fruitList
FROM tableName
GROUP BY personName
You'll want to use group_concat here.
SELECT name, group_concat(fruit)
FROM table
GROUP BY name

mysql combining records from one table

I have a single table that uses test# as the primary key. Here is what that table looks like:
Test# Name VerbalScore readingScore Notes
1 Bobby 92 Good job
2 Bobby 40 You Suck Bobby
The problem is I want to view and be able to see when there are multiple verbal scores for the same Name (so be able to see if the person took the same test more than once).
I want to have some kind of select statement to get this result from the above table:
1 Bobby 92 40 Good job, You Suck Bobby
Is that possible?
I am not totally sure I understand what you mean by "see when there are multiple verbal scores" but with mysql 5+, try
SELECT
Name,
GROUP_CONCAT(VerbalScore),
GROUP_CONCAT(readingScore),
GROUP_CONCAT(Notes)
FROM
myTable
GROUP BY
Name;
GROUP_CONCAT is a mysql specific grouping function.

how to search a word from varchar(comma separated) field in mysql?

i have a table
table_movie
mid muid actor_name movie_list(varchar)
18 act_6 tom hanks mov_18,mov_19,mov_2,mov_22,mov_23
21 act_9 jhonny depp mov_1,mov_10,mov_20,mov_22,mov_3,mov_9
28 act_16 bruce willis mov_18,mov_19,mov_2,mov_22,mov_23
29 act_19 jhon trovolta mov_1,mov_10,mov_20,mov_22,mov_3,mov_9
now i want to dispplay only those actor_name and muid which have mov_1( which comes from php) in their movie_list
if i use EXIST then it show error, my query is written below
`SELECT muid,actor_name FROM table_movie WHERE $movieID EXIST( movie_list)`
i also tried with RLIKE but no results!:(
please tell me how to search a single word from a varchar field
NOTE
my table engine is INNODB so fultext search concept also fails
What about
SELECT muid,actor_name FROM table_movie WHERE movie_list LIKE '%,$movieID,%'
OR movie_list LIKE '%,$movieID'
OR movie_list LIKE '$movieID,%'
OR movie_list LIKE '$movieID'
?
Edit: I modified the query to take the comments into account. A bit ugly but I guess it would work. Forget about performance. Another problem would be titles with comma in it.
If you can modify the schem you could have a 'movie' table and a 'actor_movie' table.

Running count of distinct values in Access

I have data stored as below in an MS Access database:
Date User
20090101 1001
20090101 1002
20090102 1001
20090103 1001
20090103 1003
I'm attempting to create a query which shows the daily running count of unique users. For example:
Date Daily Count Unique User Running Count
20090101 2 2
20090102 1 2
20090103 2 3
What's the best way to achieve this?
In most SQL implementations you could select using the aggregate function count(distinct user). But Access doesn't support that construct. I think the best you could do is to select the distinct values in a subquery and count them.
I was going to write a query but this link seems to do a good job.
HTH
Tom
Your query will look something like this...can't test it without the data though:
SELECT Date, Count(Date) As [Daily Count], Count(User) As [Unique User Running Count]
FROM TableName
GROUP BY Date
I did it! A simple solution is the best: no SQL coding needed.
In Access, Query Design,
Column 1 =
Field=Date
tablename=yourname
Total=Groupby
Column2 =
Field=Date
Table=yourname
Total=Count