How to make such a table? enter image description here

Tried, but the result is not the same

DROP TABLE IF EXISTS theme; DROP TABLE IF EXISTS votesres; CREATE TABLE votesres ( id int PRIMARY KEY AUTO_INCREMENT, yes int, no int ) ENGINE InnoDB; CREATE TABLE theme ( themeid INTEGER PRIMARY KEY AUTO_INCREMENT, name varchar(30) DEFAULT '', votes INT , FOREIGN KEY (votes) REFERENCES votesres (id) ) ENGINE InnoDB; INSERT INTO theme (name) VALUES ('sd'); INSERT INTO votesres(yes) VALUES (2); INSERT INTO votesres(no) VALUES (2); select * from theme; 
  • Why do you complicate your life? In your option to extract information you need to do a JOIN. In addition, votesres.id must be a non-auto-incremental and foreign key to the themeid . Because you have a 1 to 1 relationship. In your case, it suffices to make the columns votes_yes and votes_no in the theme table - ArchDemon
  • As already mentioned above in this case, the columns yes and no should be stored in the theme table itself. Such a structure would be needed now if you could have more than 1 (including 10 or more) themes for which the same is valid. record votesres. As for foreign key announcements, they are needed by the database only to maintain referential integrity, so that a theme cannot record a value for votes that does not have a voteres record. And it was impossible to remove the entry from the votes res referenced. - Mike
  • And any data output you describe yourself. The presence of keys does not affect the select * from one table; it always provides data for only one table. To output data from several tables, slightly more complex queries are used. In your case, you yourself specify in the query join with another table and specify the conditions for their association (the keys will not look in this case either). And among other things, you didn’t specify a value for the votes field when inserting a record, so there is now NULL and the record is not related to the votesres table. Especially since you inserted 2 entries into it (2, NULL), (NULL, 2) - Mike

0