Skip to content
Advertisement

SQL How do I query a many-to-many relationship

How do I select posts that contain a specific tag if there is a many-to-many relationship between posts and tags? The problem I am having is that because of the where tag.name = ‘xxx’, only that tag is selected. I want to select all posts that have the tag specified, together with all of their tags, e.g., Currently what I

How to write a query to produce counts for arbitrary value bands?

My table had 3 fields: id and unit. I want to count how many ids have <10, 10-49, 50-100 etc units. The final result should look like: This is the query that returns each id and how many units it has: How can I build on that query to give me the category, countIds result? Answer edit: changed sum() to

Getting first day of the week in MySql using Week No

How do I get the first day of a given week whose week number is available? For example as I write this post we are at WEEK 29.I would like to write a MySQL query that will return Sunday 18 July using this WEEKNO 29 as the only available parameter. Answer You can use: This would give you the Monday

Delete duplicate records in SQL Server?

Consider a column named EmployeeName table Employee. The goal is to delete repeated records, based on the EmployeeName field. Using one query, I want to delete the records which are repeated. How can this be done with TSQL in SQL Server? Answer You can do this with window functions. It will order the dupes by empId, and delete all but

Excel 2003 send date parameters to SQL query

I have a few worksheets that use sql queries to retrieve data. I would like all of these sheets to query data based on the same date range entered by a user in excel. eg. I would enter somewhere in a form or in a cell a date range and retrieve the value in sql to obtain data based on

Advertisement