Skip to content

sql join gives cumulative results

I want to join county and county_type tables and get only those county that doesnt have a type =30. From below example id = 1 and 3 should only be the expected output county output: Tried this: what i am getting is cumulative: Answer You want not exists:

How to union all, but separate the columns in mySQL

The first query returns the data for the last 7 days, and returns 90 in total, while the second query returns data for the previous 7 days, returns 55 in total. Current output is: But the output should be: Answer You can use conditional aggregation:

Get the number of the weekday from each date in a date list

DB-Fiddle Expected Results: I want go get the number of the weekday for each date in the table dates. Therefore, I tried to go with the solution from this question but could not make it work: How do I need to modify the query to get the expected result? Answer Get rid of the date keyword it is only needed

Email address lookup in SQL Server

We have a large subscriber database and have a lookup based on email address of type nvarchar(100). It sometimes times out probably because of a large scan of it. I want to improve this, but weary of some of the options. Would an index on it be ok, I can handle the additional storage if needed, or a computed …

SQL subtracting 2 subqueries

Fairly new to SQL and I wanted to see if I could get some help with subtraction. I want to subtract studentstaken – studentsnotreviewed and then as assign the alias total to the operation. I was thinking something along the lines of But getting some syntax problems I’m not too sure about. [Sample …

Create a string from inserted.id via trigger

I’m creating a trigger on insert that will create a new record in another table using the id from the newly inserted row. I need to format the id before I insert it into the other table. This is my …