The Web Design Group

... Making the Web accessible to all.

Welcome Guest ( Log In | Register )

> Creating a view from multiple tables
tudsy
post Aug 5 2018, 11:32 PM
Post #1


Advanced Member
****

Group: Members
Posts: 246
Joined: 30-September 14
Member No.: 21,611



Hi

I have 4 tables, CustomersArt,Customers,subscribers and emailcomm.

My question is, how do i create a view from these 4 tables with the column email ?

I have done a view from one table (see below):

$query = "CREATE VIEW ecovib2d AS SELECT email FROM CustomersArt";


Any help will be appreciated.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
 
Reply to this topicStart new topic
Replies
CharlesEF
post Aug 21 2018, 02:43 PM
Post #2


Programming Fanatic
********

Group: Members
Posts: 1,981
Joined: 27-April 13
From: Edinburg, Texas
Member No.: 19,088



I don't see anything wrong with the syntax. As I said before, the 4 tables share some column names. Maybe you need to specify column names instead of using the * character and use AS when column names are duplicated. Have you tested using only 1 joined table? Test with 2 tables that don't share any column names. If it works then add another table join to the test. If you start getting errors when column names are duplicated then you know you can't use the * character.

And, I'm not sure 'FULL JOIN' is valid. I don't see it in the MySQL documentation. But, maybe I just missed it.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
tudsy
post Aug 26 2018, 12:48 AM
Post #3


Advanced Member
****

Group: Members
Posts: 246
Joined: 30-September 14
Member No.: 21,611



QUOTE(CharlesEF @ Aug 22 2018, 05:13 AM) *

I don't see anything wrong with the syntax. As I said before, the 4 tables share some column names. Maybe you need to specify column names instead of using the * character and use AS when column names are duplicated. Have you tested using only 1 joined table? Test with 2 tables that don't share any column names. If it works then add another table join to the test. If you start getting errors when column names are duplicated then you know you can't use the * character.

And, I'm not sure 'FULL JOIN' is valid. I don't see it in the MySQL documentation. But, maybe I just missed it.



Hi

Here is the latest query:

$query = "CREATE VIEW ecovib2d AS
SELECT Customers.Customersitemid,Customers.email,Customers.name,Customers.Price,Customers.terms,Customers.Age,Customers.Date,Customers.Softbought,CustomersArt.CustomersArtitemid,CustomersArt.email,CustomersArt.graphic,CustomersArt.name,CustomersArt.Price,CustomersArt.Age,CustomersArt.Date
FROM Customers join CustomersArt on Customers.Customersitemid = CustomersArt.CustomersArtitemid
WHERE email ='$Email'";

but now I get this error:

Error Message: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '='ecovib2d@live.com'' at line 4

Any help will be appreciated.

Thanks.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
CharlesEF
post Aug 26 2018, 02:39 AM
Post #4


Programming Fanatic
********

Group: Members
Posts: 1,981
Joined: 27-April 13
From: Edinburg, Texas
Member No.: 19,088



QUOTE(tudsy @ Aug 26 2018, 12:48 AM) *
$query = "CREATE VIEW ecovib2d AS
SELECT Customers.Customersitemid,Customers.email,Customers.name,Customers.Price,Customers.terms,Customers.Age,Customers.Date,Customers.Softbought,CustomersArt.CustomersArtitemid,CustomersArt.email,CustomersArt.graphic,CustomersArt.name,CustomersArt.Price,CustomersArt.Age,CustomersArt.Date
FROM Customers join CustomersArt on Customers.Customersitemid = CustomersArt.CustomersArtitemid
WHERE email ='$Email'";

Based on the column names you posted earlier your query makes no sense. Your not using the same column names. Try this:
CODE
$query = "CREATE VIEW ecovib2d AS
         SELECT
         Customers.Itemid, Customers.email, Customers.name, Customers.Price, Customers.terms, Customers.Age, Customers.Date, Customers.Softbought,
         CustomersArt.Graphic
         FROM Customers JOIN CustomersArt ON Customers.Itemid = CustomersArt.Itemid
         WHERE Customers.email ='$Email'";
Most of your problems were typos, I think. Also, I didn't include any columns with duplicate names. First see if this query works. If it does then you can try adding columns with the same name. I have already given you an example of this, check post #7. That post uses the column 'name' from 3 tables. Notice the variable name next to each one?
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post

Posts in this topic
tudsy   Creating a view from multiple tables   Aug 5 2018, 11:32 PM
CharlesEF   You need to look in to INNER JOIN or OUTER JOIN to...   Aug 6 2018, 01:42 PM
tudsy   You need to look in to INNER JOIN or OUTER JOIN t...   Aug 6 2018, 01:57 PM
CharlesEF   You still don't tell me what columns you want ...   Aug 6 2018, 02:07 PM
tudsy   You still don't tell me what columns you want...   Aug 6 2018, 11:30 PM
tudsy   Hi A solution: “CREATE VIEW ecovib2d AS SELECT...   Aug 10 2018, 03:55 AM
CharlesEF   No. You're not joining any tables. Here is a...   Aug 10 2018, 12:13 PM
CharlesEF   You should start by joining just 1 table. I haven...   Aug 10 2018, 03:31 PM
CharlesEF   Ok, here is a hint. Since you never said which co...   Aug 11 2018, 12:21 PM
tudsy   Ok, here is a hint. Since you never said which c...   Aug 11 2018, 10:38 PM
CharlesEF   I don't think so, you need to change the ON pa...   Aug 12 2018, 12:16 AM
tudsy   I don't think so, you need to change the ON p...   Aug 14 2018, 08:21 PM
tudsy   I don't think so, you need to change the ON ...   Aug 14 2018, 09:53 PM
CharlesEF   Just in case, your error is here: WHERE email =...   Aug 15 2018, 01:06 AM
CharlesEF   Correction: Since the entire query should be enclo...   Aug 15 2018, 12:12 PM
tudsy   Hi I have another problem. Here is a query: ...   Aug 15 2018, 11:27 PM
CharlesEF   I don't see anything wrong, as far as syntax. ...   Aug 16 2018, 12:13 AM
tudsy   I don't see anything wrong, as far as syntax....   Aug 20 2018, 08:11 PM
CharlesEF   I don't see anything wrong with the syntax. A...   Aug 21 2018, 02:43 PM
tudsy   I don't see anything wrong with the syntax. ...   Aug 26 2018, 12:48 AM
CharlesEF   $query = "CREATE VIEW ecovib2d AS ...   Aug 26 2018, 02:39 AM
tudsy   Hi Thanks for that. I renamed the column names w...   Sep 4 2018, 11:49 PM
CharlesEF   $query ="SELECT Customers.Customersitem...   Sep 5 2018, 12:11 AM
tudsy   $query ="SELECT Customers.Customersite...   Sep 5 2018, 12:15 AM
CharlesEF   Create a new PHP script and place this code in it....   Sep 6 2018, 12:24 AM
tudsy   Create a new PHP script and place this code in it...   Sep 6 2018, 09:54 PM
CharlesEF   That tells me the script did run but returned no r...   Sep 6 2018, 10:26 PM
tudsy   That tells me the script did run but returned no ...   Sep 6 2018, 10:59 PM
tudsy   That tells me the script did run but returned no ...   Sep 6 2018, 10:59 PM
CharlesEF   That doesn't help much. Customers contains no...   Sep 7 2018, 12:40 AM
tudsy   That doesn't help much. Customers contains n...   Sep 7 2018, 01:05 AM
CharlesEF   I want the visitor to look at his/her data (the w...   Sep 7 2018, 01:48 AM
CharlesEF   I want to add that if you are happy with your data...   Sep 7 2018, 05:40 PM
tudsy   I want to add that if you are happy with your dat...   Sep 7 2018, 08:50 PM
CharlesEF   Results: Viewing your data from ECOVIB2DS databas...   Sep 7 2018, 09:08 PM
tudsy   Results: Viewing your data from ECOVIB2DS databa...   Sep 7 2018, 10:38 PM
tudsy   [quote name='CharlesEF' post='136182' date='Sep 8...   Sep 7 2018, 10:47 PM
CharlesEF   Telling me about an error but now showing the quer...   Sep 7 2018, 11:46 PM


Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 



- Lo-Fi Version Time is now: 9th May 2024 - 12:21 PM