logo
down
shadow

SQL joining tables issue


SQL joining tables issue

By : user2951334
Date : November 18 2020, 01:01 AM
hope this fix your issue your query looks very strange for me, try this version with proper order:
code :
SELECT Project.PROJNAME
FROM
    PROJECT
JOIN
    SHIPMENT
ON PROJECT.PROJNUM = SHIPMENT.PROJNUM
JOIN
    PARTS
ON SHIPMENT.PNUM = PARTS.PNUM
JOIN
    SUPPLIERS
ON SHIPMENT.SNUM = SUPPLIERS.SNUM
WHERE
SUPPLIERS.SNAME IN ('S1', 'S2')


Share : facebook icon twitter icon
Joining two tables Issue

Joining two tables Issue


By : bedir
Date : March 29 2020, 07:55 AM
may help you . If you don't want a column repeated, you can't use SELECT * FROM but rather you will need to use the column names you want to select.
You aren't getting the 4000 result you are expecting because you are doing an inner join on a field that doesn't exist in the other table. (Azeem = 4000, but no note_contact exists for user 4000).
code :
select
    a.note_id,
    a.note_contact,
    b.contact_text,
    b.note_text
from
    contacts a
        left outer join notes b
            on a.contact_id=b.note_contact
where
    a.contact_text like '%azeem%'
    or b.note_text like '%azeem%'
mysql> CREATE TABLE `contacts` (
    ->   `contact_id` int(4) DEFAULT NULL,
    ->   `contact_text` varchar(40) DEFAULT NULL,
    ->   `contact_email` varchar(40) DEFAULT NULL
    -> ) ENGINE=InnoDB DEFAULT CHARSET=latin1;
Query OK, 0 rows affected (0.00 sec)

mysql> 
mysql> CREATE TABLE `notes` (
    ->   `note_id` int(3) NOT NULL AUTO_INCREMENT,
    ->   `note_contact` int(4) DEFAULT NULL,
    ->   `note_text` tinytext,
    ->   PRIMARY KEY (`note_id`)
    -> ) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=7 ;
Query OK, 0 rows affected (0.00 sec)

mysql> 
mysql> INSERT INTO `contacts` (`contact_id`, `contact_text`, `contact_email`) VALUES
    -> (4000, 'azeem', 'azeem@big.com'),
    -> (4001, 'nawaz', 'azeem@big.com'),
    -> (4002, 'nawaz', 'azeem@big.com');
Query OK, 3 rows affected (0.00 sec)
Records: 3  Duplicates: 0  Warnings: 0

mysql> 
mysql> INSERT INTO `notes` (`note_id`, `note_contact`, `note_text`) VALUES
    -> (1, 4001, 'I am text1'),
    -> (2, 4001, 'I am text2'),
    -> (3, 4001, 'my name is azeem'),
    -> (4, 4001, 'come here'),
    -> (5, 4001, 'I don''t want to'),
    -> (6, 4003, 'My text is clear.');
Query OK, 6 rows affected (0.01 sec)
Records: 6  Duplicates: 0  Warnings: 0
mysql> select
    -> b.note_id,
    -> b.note_contact,
    -> a.contact_text,
    -> b.note_text
    -> from
    -> contacts a
    -> left outer join notes b
    -> on a.contact_id=b.note_contact
    -> where
    -> a.contact_text like '%azeem%'
    -> or b.note_text like '%azeem%';
+---------+--------------+--------------+------------------+
| note_id | note_contact | contact_text | note_text        |
+---------+--------------+--------------+------------------+
|    NULL |         NULL | azeem        | NULL             |
|       3 |         4001 | nawaz        | my name is azeem |
+---------+--------------+--------------+------------------+
2 rows in set (0.00 sec)
$where_clause = " where contacts.contact_text like '%".addslashes($_GET['s'])."%' or notes.note_text like '%".addslashes($_GET['s'])."%'";
$result = mysql_query("select distinct contacts.contact_id from contacts left outer join notes on contacts.contact_id=notes.note_contact $where_clause")
Issue in joining 4 tables

Issue in joining 4 tables


By : John Gravel
Date : March 29 2020, 07:55 AM
hop of those help? INNER JOINs will only show rows where all tables provide non-null values. Since your schema contains optional providers, you will need to use some kind of outer join instead (e.g. LEFT JOIN):
code :
SELECT Client_Portfolio.*,
Client.Name as "Client Name",
Provider.Name as "Provider Name",
Portfolio.*
FROM Client_Portfolio
INNER JOIN Client ON Client_Portfolio.idClient = Client.idClient
INNER JOIN Portfolio ON Client_Portfolio.idPortfolio = Portfolio.idPortfolio
-- show row even if it does not have a provider:
LEFT JOIN Provider ON Portfolio.idProvider = Provider.idProvider
Issue while joining many tables

Issue while joining many tables


By : To Alex
Date : March 29 2020, 07:55 AM
hope this fix your issue Associations between menu_details and pizza_menu were made wrong so I chaged menu_details to :
code :
--------------------------------------------------------
| id | order_details_fk | pizza_menus_fk | products_fk |
--------------------------------------------------------
| 17 |        132       |       25       |     39      |
| 18 |        132       |       26       |     40      |
| 19 |        132       |       27       |     41      |
| 20 |        132       |       28       |     42      |
--------------------------------------------------------
SELECT   DISTINCT products.product_name, sizes.pizza_size_name 
FROM     products, menu_details, pizza_menus, sizes 
WHERE    products.product_id = menu_details.products_fk 
AND      menu_details.pizza_menus_fk = pizza_menus.id 
AND      pizza_menus.size_id = sizes.pizza_size_id 
AND      menu_details.order_details_fk = 132
SQL: issue joining tables

SQL: issue joining tables


By : Benny Haer
Date : March 29 2020, 07:55 AM
will be helpful for those in need You might need to do inner join by two columns attr_value_id and attr_id. Try this query:
code :
SELECT     dbo.select_attributevalue.attr_value, dbo.select_attributevalueassign.itm_id
FROM         dbo.select_attributevalueassign 
    INNER JOIN dbo.select_attributevalue ON 
    dbo.select_attributevalueassign.attr_id = dbo.select_attributevalue.attr_id
    AND dbo.select_attributevalueassign.attr_value_id = dbo.select_attributevalue.attr_value_id
WHERE     (dbo.select_attributevalueassign.itm_id = 396)
Issue in joining two tables

Issue in joining two tables


By : Jason Mooneyham
Date : March 29 2020, 07:55 AM
I wish did fix the issue. In MySQL, character is a reserved word, although it is not a reserved word in other databases. The list of MySQL reserved words is here. You use backticks to escape values in MySQL.
You should also use proper, explicit join syntax:
Related Posts Related Posts :
  • Exception while returning an empty Associative array from PLSQL function
  • How to create a database snapshot in SQL Server 2008 R2
  • Query speed and expressions with constant value
  • How to do a complex calculation as this sample
  • Passing a ResultSet into a Postgresql Function
  • Netsuite custom formula field using a CASE statement with multiple WHEN conditions returning "invalid expression&qu
  • Execute query command (dynamic sql) runs faster than ordinary query
  • How to extract only numbered rows from a column
  • INSTEAD OF DELETE trigger (Postgresql)
  • Oracle Apex, when a report with sql is created, how do i get it return after entering in to a text box?
  • Select records based on two tables where one column in one table starts with the records from another tables column usin
  • How to write select using two ids combination in Oracle 11g
  • Frequently use of 'UPDATE STATISTICS WITH FULLSCAN' is normal?
  • need query for this simple pulling data sql server
  • Sql query by using decode to show grades of employee
  • Not a single function error in Oracle
  • Oracle SQL optimizer's behavior when dealing with ORs and row-independent predicates (such as functions returning same v
  • Combining output of two or more select statement
  • Must Declare Scalar Variable Exception
  • Postgres Calculate Difference Using Window Functions
  • SQL Server : unsure how to retrieve selected records
  • SQL unique field: concurrency bugs?
  • Query to get the next identity?
  • SQL Server Adding summing values based on the month
  • Join on month if available else join on latest month
  • How to solve error: ORA-01406 fetched column value was truncated?
  • Selecting Field Multiple Times using OR
  • Which SQL datatype can be used to store mobile numbers in numeric forms, without including characters like brackets and
  • Oracle SQL - "Not a group by expression" after adding CASE statements
  • Runnning total of unique string values in column over days
  • VB.Net to AccessDB by SQL - INSERT INTO with parameters error
  • SQL/Excel/VBA - UPDATE query: 'Syntax Error (missing operator) in query expression'
  • Code to combine two sql queries
  • Setting SQL Date field value based off Week Number and Day Number Field
  • SQL query to find matching records but with differences in case sensitivity?
  • How to sort record inside views in SQL Server 2008
  • How to link the output of teradata sql query to an excel sheet?
  • Matching sets in SQL when cross-referencing
  • error even after following Microsoft format in SQL
  • Increase price by percentage, results rounded
  • Can we Use "Case" in a ColdFusion Query-of-Query
  • displaying 'Active' for a row which has 'A' as value
  • Using pattern search in SQL Server Query
  • SQL - how to group transactions for a certain date pattern?
  • How to Index SQL with multiple AND conditions nested inside OR
  • SQL rank with priority
  • Does BigQuery support SubQueries?
  • Any ideas for persisting H2 Database In-Memory mode transaction?
  • How to improve SQL query performance (correlated subqueries)?
  • Filter repeated columns in Oracle
  • SQL Server join on whichever column has value populated
  • use sql stored procedure to insert data which is returned from a query stored in a table
  • Query not working1
  • SQL - using an alias in a where clause in a subquery
  • How to search for a whole word with special char using oracle contains?
  • Production Perfomance of using SELECT * statements?
  • String concatenation not working as expected in SELECT statement
  • How to detect which stored procedures UPDATE or INSERT into a certain TABLE?
  • Select statement inside CASE - SQL
  • .Net Float error 4 - float(4) = 4.44089209850063E-16
  • shadow
    Privacy Policy - Terms - Contact Us © ourworld-yourmove.org