All Questions

85
votes
13answers
12461 views

How to filter SQL results in a has-many-through relation

Assuming I have the tables student, club, and student_club: student { id name } club { id name } student_club { student_id club_id } I want to know how to find all students ...
29
votes
6answers
12465 views

Select values that meet different conditions on different rows?

This is a very basic query I can't figure out.... Let's say I have a two column table like this: userid | roleid --------|-------- 1 | 1 1 | 2 1 | 3 2 | 1 I w...
6
votes
8answers
4948 views

How do I avoid dynamic SQL when using an undetermined number of parameters?

I have a StackOverflow-like tagging system for a database I'm working on. And I'm writing a stored procedure that looks for results based on an undetermined number of tags in a WHERE clause. There c...
3
votes
2answers
1918 views

Select in a many-to-many relationship in MySQL

I have two tables in a MySQL database, Locations and Tags, and a third table LocationsTagsAssoc which associates the two tables and treats them as a many-to-many relationship. Table structure is as f...
2
votes
3answers
225 views

Can you solve this simple SQL query?

Suppose it's a website that sells photo cameras. Here are my entities (tables): Camera: A simple camera Feature: A feature like: 6mp, max resolution 1024x768, The thing is between cameras and feat...
5
votes
9answers
6321 views

What is a SQL statement to select an item that has several attributes in an item/attribute list?

Say I have a table that has items and attributes listed like, frog green cat furry frog nice cat 4 legs frog 4 legs From the items column I want to select unique objects that have ...
0
votes
4answers
222 views

Querying based on a set of Named Attributes/Values

I am working with a set of what is essentially Attribute/Value pairs (there's actually quite a bit more to this, but I'm simplifying for the sake of this question). Effectively you can think of the t...
8
votes
2answers
8846 views

SQL one-to-many match the one side by ALL in many side

In the following one to many CREATE TABLE source(id int, name varchar(10), PRIMARY KEY(id)); CREATE TABLE params(id int, source int, value int); where params.source is a foreign key to source.id I...
1
votes
2answers
110 views

How to do this query in Mysql?

I have 3 tables, message, subject and message_subject_rel. The idea is to have messages that can relate to a lot of subjects and then do a cross subject search. Lets say I have a message: Id: 1, Mes...

Previous Next