Skip to content

Tag: sql

select where time = x or later

I have a table with columns username and timestamp . When a username is entered the current timestamp is as well. I would like to fetch the rows of all the new users from a certain time until now, but the start time varies. Lets make it a timestamp represented by x. I would like to use SQL to select

SQL : remove last comma in string

I have a text memo field in SQL table that I need to remove the last character in the field if it’s a comma. So, for example, if I have these rows, I need to remove the commas from rows 2 and 4. The output would be: Any ideas? Answer Using REVERSE and STUFF: First, you want to TRIM your

How to check the query is using the indexes in mysql

I have a SQL query with where clause, I have created the index for the columns which are being used in the where clause. How can I check the query is using the indexes for these columns? Answer Write “explain ” in front of your query. The result will tell you which indexes might be used. For examp…

C# sql create one connection and open and close for each query

I recently inherited a C# Web app that creates a new connection for every query like so: I understand that this is typically the best way to do it, but is it acceptable or “best practice” to have the constructor create the connection object, and then have each method/Query open and then close that…

Find out available days and slots for doctor appointment

I have three tables: TimeSlotToken is the number of patients a doctor will see in his TimeSlot. TimeSlot 1, 2, and 3 are Morning, Afternoon and Evening respectively. I need to find the days where the TimeSlot is not full, i.e TimeSlot token is less than total bookings on that particular day and that slot. Sin…

How to retrieve count of records in SELECT statement

I am trying to retrieve the right count of records to mitigate an issue I am having. The below query returns 327 records from my database: Where I run into trouble is trying to reconcile that with the below query. One is for showing just a count of all the particular students the other is showing pertinent in…