logo
down
shadow

Joining two foregin keys in the same table references the same primary key


Joining two foregin keys in the same table references the same primary key

Content Index :

Joining two foregin keys in the same table references the same primary key
Tag : mysql , By : user183676
Date : January 12 2021, 09:11 PM

hope this fix your issue Your query is wrong either way. But the reason for getting zeros as result are probably these conditions: b.userId = u.userId and b.userId = f.followed AND f.follower = u.userId.
IF b.userId = u.userId and b.userId = f.followed then f.followed = u.userId
SELECT
count(DISTINCT b.bookId) AS booksCount,
count(br.bookId) AS reviewsCount,
(SELECT COUNT(*) FROM Followers AS f WHERE f.followed = u.userId) AS followersCount
FROM Users AS u
LEFT JOIN Books       AS b  ON b.userId  = u.userId
LEFT JOIN BooksReview AS br ON br.bookId = b.bookId 
WHERE u.userId = 'dbb21849-ccce-4af1-aa0f-6653919bf956'

Comments
No Comments Right Now !

Boards Message :
You Must Login Or Sign Up to Add Your Comments .

Share : facebook icon twitter icon

Doctrine composite primary key as well as foregin keys


Tag : development , By : Dennizzz
Date : March 29 2020, 07:55 AM
To fix the issue you can do Validate your schema - these mappings are incorrect. Either a field is a column, or it is an association. Having both mappings on the same field is not allowed:
/**
 * ilan_emlakOzellik
 *
 * @ORM\Table()
 * @ORM\Entity
 */
class ilan_emlakOzellik
{

    /**
     * @ORM\Id
     * @ORM\ManyToOne(targetEntity="ilan")
     * @ORM\JoinColumn(name="ilanId")
     */
    private $ilanId;

    /**
     * @ORM\Id
     * @ORM\ManyToOne(targetEntity="emlakOzellik")
     * @ORM\JoinColumn(name="ozellikId")
     */
    private $ozellikId;

How to insert record which has foregin key referenced to primary key of another table in PHP Script?


Tag : php , By : krs
Date : March 29 2020, 07:55 AM
I hope this helps you . You never executed the query that's supposed to return the country ID. You just set $CountryId to the SQL string. It should be:
$sql = "SELECT CountryId FROM tbl_country_master WHERE CountryName='$CountryName'";
$result = mysqli_query($con, $sql);
$row = mysqli_fetch_assoc($result);
if ($row) {
    $CountryId = $row['CountryId'];
}
$sql = "INSERT INTO tbl_state_master(StateName, Description, CountryId)
        SELECT '$StateName', '$Description', CountryId
        FROM tbl_country_master WHERE CountryName='$CountryName'";

Adding a new row to a table with many foregin keys


Tag : chash , By : Jakub Filak
Date : March 29 2020, 07:55 AM
seems to work fine I have a small problem with setting up relations between tables in entity. Basically I have three models: AppUser, Assignment and CompletedAssignment. ,
AppUserID has no value.
[Bind(Include = "ID,AssignmentID,UserID,CompletionDate")]
[Bind(Include = "ID,AssignmentID,AppUserID,CompletionDate")]

How to fix foreign key constraint when trying to references two primary keys from the same table?


Tag : mysql , By : Giles
Date : March 29 2020, 07:55 AM
wish of those help Misson: , One single foreign key has to be created for this like:
CREATE TABLE IF NOT EXISTS TestBridge2
(
TestBridgeID integer Primary key,
WorkOrder varchar(15),      
Date datetime,                  

Foreign key (WorkOrder, Date) references TestInformation2 (WorkOrder, Date)
) ENGINE = InnoDB;

Drop a table with primary key having foregin key reference to another table


Tag : sql , By : mgaspar
Date : March 29 2020, 07:55 AM
Related Posts Related QUESTIONS :
  • How to pass the data from modal to MYSQL using VueJS
  • MYSQL - get a row from a table in every database
  • date type casting in npm package?
  • GROUP BY a, b VS GROUP BY b, a
  • How to store multiple values on a mysql table
  • 2 SELECT in a query with ORDER BY
  • BigQuery: How to run cohort / retention analysis for userbase across 2.5 years?
  • Can't connect local database. Sequel Pro encountered an unexpected error
  • How do I change the auto increment counter in MySQL from +1 to +43
  • How to query non duplicate rows but keep the primary key
  • How to group all scores by username in a table and display rank?
  • How to remove timestamp with the date using sql query?
  • Modify SQL query to get data only from past 2 months
  • change engine type from MyISAM to InnoDB
  • Need mysql query to find total sum as per matched query
  • json_table syntax and structure
  • Is there any way in sql query to rank certain value in ordered set of records such that ranking reset after it encounter
  • not able to login in google cloud storage sql instance
  • Inserting data into MySQL database with VBA
  • Make (user_id&music_id) unique in Likes table and Dislikes table
  • Can't do 50k insertion using bulkCreate
  • SQL syntax to get data IN date
  • How to get 4-byte emojis to store correctly in mysql 5.7?
  • How to create an in-memory database for PHPUnit testing?
  • How to write an SQL query to fetch the id in a column that has all the required data in some other column?
  • Invalid COLUMN in the select list because it is not contained in either an aggregate function or the GROUP BY clause
  • How to get actual index number of rows in MySQL when using Where clause
  • SQL Table Relationship
  • How to fix "FUNCTION doesnt exist" error in mysql?
  • Importing .bak from MSSQL into MySQL database
  • Aggregate query with distinct subquery kills every connection
  • How do i use and with multiple or condition?
  • How to fix 'The server requested authentication method unknown to the client [caching_sha2_password]' on docker compose?
  • In Mysql How to fetch distinct row value from a column1 and sum(column 2 row value) group by invoice number
  • MySQL ORDER BY field with a toggle
  • How to insert system's Date into Table
  • Aws lambda function too many connection issue rds
  • MYSQL - join 2 tables - sort in time
  • SQL code to select records where field_A matches the field_A value of a certain field_B value
  • How to model Amazon Redshift external table for changing column structure?
  • Query the list of CITY names from STATION that do not start with vowels and do not end with vowels. Your result cannot c
  • how to get rows with time for each minute for last 30 minutes
  • SQL Query With Between ,AND & OR in Where Clauses Not Given Correct Answers
  • ER_PARSE_ERROR: You have an error in your SQL syntax;
  • How to write normal sql queries inside controller in laravel
  • MySql query between range values(single record)
  • Set length conditions on text column in MySQL table
  • Mysql order of sorting
  • Sequelize raw queries TextRow and getting data out of it
  • Comparing the contents of two csv files, where the relation between the two files is specified in a third file?
  • Can 1 primary id link to multiple ids in one table?
  • Rewrite MySQL query and make it short
  • Why are parentheses used in JOIN USING clauses
  • Delete from row to row in phpadmin
  • Inserting Data into a table
  • How to efficiently get a entry with highest version in mysql table
  • How do I create views in dolphindb?
  • MySQL - update with inner join is creating nulls
  • Should i rather use a subquery or a combined WHERE?
  • INSERT INTO using data from other table causing ERROR 1064
  • shadow
    Privacy Policy - Terms - Contact Us © scrbit.com