Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I have 2 separate objects (A,B) no relationship between A,B
Object A has (X,Y,Z) values
Object B has (X,Y,Z,P,W) values
Values are different in A and B, for example A.Z = 4 while B.Z = 6
What is the best practice in creating tables:
Create separate tables (A,B) with values
Create table Type (A,B) and Table Value (X,Y,Z,P,W) with key to table Type.
Thanks,
For low cardinality and simple situations I would just go with:
3. Table AB with columns (X, Y, Z, P, W) and an A/B type identifier and let P, W be null for A objects
With more information I might make a different choice.
Related
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
lets say I have two MySQL tables, table A and table B. Each table has a primary key called id and a name column. I also have a third table, table C, that contains relationships between table A and table B. Each row contains two foreign keys called a_id and b_id, which, as you might expect, correspond to ids in tables A and B.
What I want to do is select a random set of 10 table A rows, but only select rows that have a relationship with specific entries in table B. I don't know which entries I'm looking for ahead of time, and I will start with their names. The names will be provided via query parameters.
I understand I should probably start with this:
SELECT * FROM `A`
ORDER BY RAND()
LIMIT 10
But I don't know how to structure the where clause.
You need something like this:
SELECT *
FROM `A` a
INNER JOIN `C` c ON
a.ID = c.a_id AND
c.b_id in (1,2,3,4) -- your entries here
-- order and limit as you wish
ORDER BY RAND()
LIMIT 10
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 2 years ago.
Improve this question
A MySQL table called SQ was created as follows,
CREATE TABLE SQ(
SQno INT PRIMARY KEY,
Question VARCHAR(100)
);
After I was trying to enter data to that table like this,
INSERT INTO SQ (SQno, Question) VALUES(
(1,'What primary school did you attend?'),
(2,'In what town or city did your parents meet?'),
(3,'In what city or town was your first job?'),
);
But there was an error occurs, and shows as this,
ERROR 1136 (21S01): Column count doesn't match value count at row 1
So, please help me to resolve this error?
You need to get rid of the outer set of parentheses; each row should have parentheses around it but not also all the rows:
INSERT INTO SQ (SQno, Question) VALUES
(1,'What primary school did you attend?'),
(2,'In what town or city did your parents meet?'),
(3,'In what city or town was your first job?')
;
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
I have a mysql database and some tables.
One table is Products: Its columns are prod_id, prod_type.
Prod_types are mobile or laptop or book.
Each of them have different attributes (eg: publisher, author for books, battery_condition, model for laptop etc).
Should I store all the data in the Products table by adding columns like 'author', 'model' etc and keep null for those columns which don't apply to my product.
For example for an entry with prod_type='book' , 'model', 'batter_condition' etc will be null. Or should I create different tables for 'book', 'mobile' and 'laptop' ?
Yes. Create new tables for Book, Mobile and Laptop. Have the product_id attribute in each of those tables. This product_id attribute is a foreign key to the primary key of table products, which is product_id as well.
Storing all data in products will result in a lot of NULL fields and will make the data storage inefficient.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
Let's say i have two tables.
Table client
ID - primary key ( 1,2,3,4,5,6)
Table Orders
OrderID - primary key
ClientID (1,2,4,5)
I need to get ROWS of table CLIENT of clients 3 and 6 (which don't have orders / are not in orders table)
This is basic query. Try your self.
select * from client where id not in (select ClientID from orders)
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
Insert a value in a column name e-mail then it display all emails seperated by comma. This email is save at different time but for same id.
Is it possible then how?
You can use GROUP_CONCAT to show the comma separated records that belong to same group,be aware of that fact GROUP_CONCAT has a default limit of 1024 characters to concat but it can be increased as mentioned in docs
CREATE TABLE Table1
(id INT ,`test` varchar(25))
;
INSERT INTO Table1
(id,`test`)
VALUES
(1,'test#test.com'),
(1,'test#test.com'),
(1,'test#test.com'),
(2,'test2#test.com'),
(2,'test2#test.com'),
(2,'test2#test.com')
;
SELECT id, GROUP_CONCAT(test) emails
FROM
Table1 GROUP BY id
Fiddle Demo