logo
down
shadow

Is it more efficient to have a table with one of its columns mostly empty or make a new table and refer to it?


Is it more efficient to have a table with one of its columns mostly empty or make a new table and refer to it?

By : user2955627
Date : November 22 2020, 10:40 AM
I wish did fix the issue. You are talking about Normalization of course it's much better to provide a way for removing redundant and null data. you have this existing table:
code :
    table1
----------------------------
role      | poster_id | name
varchar(n)| int       | varchar(n)
    table1              table2
------------------     ---------------------------
rol_id  | rol_name     rol_id   | poster_id | name
 tinyint| varchar(n)     tinyint| int       | varchar(n)


Share : facebook icon twitter icon
In mysql, what is an efficient way to get only rows in a table by a distinct value in one of that table's columns?

In mysql, what is an efficient way to get only rows in a table by a distinct value in one of that table's columns?


By : davefreiman
Date : March 29 2020, 07:55 AM
Any of those help I'm relatively new to mysql so bear with me. , This is how I would do it:
code :
SELECT mt1.ID, mt1.Name, mt1.Location 
FROM mytable mt1
JOIN (SELECT MIN(id) AS ID 
        FROM Mytable 
        GROUP BY location) mt2
    ON mt1.id = mt2.Id
Values of columns in first table refer to column names in second table. How to pull the values from second table?

Values of columns in first table refer to column names in second table. How to pull the values from second table?


By : user3026348
Date : March 29 2020, 07:55 AM
hop of those help? First post, have been searching extensively for a month for an answer to this and figured I would just ask the experts.
code :
UPDATE Table2 
SET 
Physc_Proc1 = 
    CASE WHEN Phys_Proc1 = 1 Then Table2.Physician1 
    CASE WHEN Phys_Proc1 = 2 Then Table2.Physician2 
    CASE WHEN Phys_Proc1 = 3 Then Table2.Physician3 
    CASE WHEN Phys_Proc1 = 4 Then Table2.Physician4 
    CASE WHEN Phys_Proc1 = 5 Then Table2.Physician5
    ELSE NULL 
END, 

Physc_Proc2 = 
    CASE WHEN Phys_Proc2 = 1 Then Table2.Physician1 
    CASE WHEN Phys_Proc2 = 2 Then Table2.Physician2 
    CASE WHEN Phys_Proc2 = 3 Then Table2.Physician3 
    CASE WHEN Phys_Proc2 = 4 Then Table2.Physician4 
    CASE WHEN Phys_Proc2 = 5 Then Table2.Physician5
    ELSE NULL 
END, 

PhyscProc3 = 
    CASE WHEN PhysProc3 = 1 Then Table2.Physician1 
    CASE WHEN PhysProc3 = 2 Then Table2.Physician2 
    CASE WHEN PhysProc3 = 3 Then Table2.Physician3 
    CASE WHEN PhysProc3 = 4 Then Table2.Physician4 
    CASE WHEN PhysProc3 = 5 Then Table2.Physician5
    ELSE NULL 
END, 

PhyscProc4 = 
    CASE WHEN PhysProc4 = 1 Then Table2.Physician1 
    CASE WHEN PhysProc4 = 2 Then Table2.Physician2 
    CASE WHEN PhysProc4 = 3 Then Table2.Physician3 
    CASE WHEN PhysProc4 = 4 Then Table2.Physician4 
    CASE WHEN PhysProc4 = 5 Then Table2.Physician5
    ELSE NULL 
END, 

PhyscProc5 = 
    CASE WHEN PhysProc5 = 1 Then Table2.Physician1 
    CASE WHEN PhysProc5 = 2 Then Table2.Physician2 
    CASE WHEN PhysProc5 = 3 Then Table2.Physician3 
    CASE WHEN PhysProc5 = 4 Then Table2.Physician4 
    CASE WHEN PhysProc5 = 5 Then Table2.Physician5
    ELSE NULL 
END
FROM Table2
INNER JOIN Table1
ON Table2.Account = Table1.Account
Join and Display 2 Columns from One Table refer by Another Table

Join and Display 2 Columns from One Table refer by Another Table


By : Ronny Hofsøy
Date : March 29 2020, 07:55 AM
may help you . I have 2 table , Can you try this...
code :
SELECT a.username as User_1, b.username as User_2 FROM
table_A t
JOIN table_B b on b.id = t.id_B
JOIN table_B a ON a.id = t.id_A
Can a table in SQL have multiple columns as foreign keys that refer only to one primary key of another table?

Can a table in SQL have multiple columns as foreign keys that refer only to one primary key of another table?


By : N. Antoniadis
Date : March 29 2020, 07:55 AM
To fix this issue For instance, table Companies has columns company_name, first_contact, second_contact and table contacts have columns id(PK), name, phone. Can a table (companies) in SQL have multiple columns as foreign keys that refer only to one primary key of another table (contacts)? , Yes, here's an example:
code :
mysql> CREATE TABLE Contacts (id INT PRIMARY KEY);
Query OK, 0 rows affected (0.03 sec)

mysql> CREATE TABLE Companies (id INT PRIMARY KEY, company_name TEXT,
    -> first_contact INT, second_contact INT,
    -> FOREIGN KEY (first_contact) REFERENCES Contacts(id),
    -> FOREIGN KEY (second_contact) REFERENCES Contacts(id)
    -> );
Query OK, 0 rows affected (0.03 sec)
mysql> CREATE TABLE CompanyContacts (
    -> contact_id INT NOT NULL,
    -> company_id INT NOT NULL,
    -> is_primary BOOL NOT NULL,
    -> PRIMARY KEY (contact_id, company_id),
    -> FOREIGN KEY (contact_id) REFERENCES Contacts(id),
    -> FOREIGN KEY (company_id) REFERENCES Companies(id)
    -> );
Query OK, 0 rows affected (0.04 sec)
Refer from several columns in table to single another table using foreign keys?

Refer from several columns in table to single another table using foreign keys?


By : user3708746
Date : March 29 2020, 07:55 AM
should help you out This isn't anything more complicated than a single foreign key. It has a definite smell to it that the design is less than ideal. But with no knowledge of the business requirements it is impossible to be certain or help find a better architecture.
Here is a working example as outlined in your question.
code :
create table Table2
(
    Id int identity primary key
    , Value1 varchar(10)
)

create table Table1
(
    Id int identity primary key
    , Val1 int 
    , Val2 int
    , Val3 int
    , constraint FK_Table1_Table2_Val1 foreign key (Val1) references Table2(Id)
    , constraint FK_Table1_Table2_Val2 foreign key (Val2) references Table2(Id)
    , constraint FK_Table1_Table2_Val3 foreign key (Val3) references Table2(Id)
)

insert Table2 values
('first val')
, ('second')
, ('third')

insert Table1 values
(1, 1, 3)
, (3, 2, 1)
Related Posts Related Posts :
  • select the records with the highest amount
  • Changing Mysql golbal variable
  • How to create Effective Indexing on MySQL
  • `require': Incorrect MySQL client library version
  • How to save a FirstName of a Person efficiently without duplicate entries
  • Can I store my own sql query by mysql special function and execute stored query later?
  • MySQL comma separated field query
  • Why does the same exact query produce 2 different MySQL explain results?
  • Suppress warning output in bash
  • Doctrine "on update CURRENT_TIMESTAMP" annotation (Symfony2)
  • Designing "Friend" relationships across two mysql tables
  • Importing sql file using phpmyadmin in EasyPHP
  • Easy PHP and mysql ..php cannot see database on local pc (all works on server)
  • MySQL join optimization - bypassing filesort
  • How to Select record with the maximum value in a GROUP BY?
  • MySQL Innodb Full text Proximity Search Gives Horrible Performance
  • MySQL best approach for db normalising, relationships and foreign keys
  • How to update one table based on the count value of another table while matching ids?
  • MAMP Pro 5.1.1-terminates MySQL when quitting
  • SQL - Get date of most votes cast
  • "Fuzzier" search in mysql
  • Tracing mysqld Using SystemTap
  • SELECT + INSERT + Query Cache = MySQL lock up
  • SQL vs. NoSQL for medium complexity search systems
  • SQL Error when creating table
  • Is it possible to write a query to compare rows to other rows in same table?
  • Display all duplicate records based multiple columns
  • summing time column in mysql
  • InnoDB: Cannot open table
  • Why is IN() considered O(logN) operation?
  • Can a deadlock occur on commit?
  • Is there a fast way to do a '%phrase%' search in any DB?
  • Is using an IN over a huge data set a good idea?
  • How can I know if a table is already arranged in ascending order in MySQL?
  • MySQL - Designing database for a simple game
  • Why am I getting "Host '192.168.1.220' is not allowed to connect to this MySQL server"?
  • what type of password hash? possible mysql hash?
  • MySQL - Using a date range vs functions
  • Using IS NULL and COALESCE in OrderBy Doctrine Querybuilder
  • How to merge MySQL columns into one column if there are empty values in the table?
  • Cardinality Confusion
  • Renaming column multiple ids in SELECT
  • Group all from and to messages per user
  • How to handled the null values in WHERE IN condition in mysql
  • Is it okay to update primary key field to shift a record to the top?
  • Stop query through pdo
  • How to check whether particular value in field in MySQL exists
  • Execute a statement for every table in a database
  • insertion 74G data into mysql table cost more then 2 days, how to improve insert performance
  • Where can I see the differents "Hibernate Console Configurations" in Eclipse
  • MySql | relational database vs non relational database in terms of Performance
  • Exporting mysql database using mysqldump including procedures
  • Trigger MySQL not working
  • How do I update values for individual rows quickly?
  • MySQL join query with multiple where condition
  • MySQL stored procedure is not working
  • MySQL - Order By exact match at the end
  • Select max date or null date from same table MySQL
  • Best solution workaround for needing a mysql event on insert?
  • MySQL select several columns of several tables at the same time without using JOIN
  • shadow
    Privacy Policy - Terms - Contact Us © ourworld-yourmove.org