How can i user join on this SQL? - sql

okay i have got this sql statement which someone helped me on here to make this statement the only problem im facing that i want catDesc from te_category table to be appear on my 'Category' table on main page but instead of that i'm getting catID from te_events
This is the code i got from stackoverflow.
$sql = "SELECT * FROM te_events
JOIN te_venue
ON te_venue.venueID = te_events.venueID
WHERE te_events.eventID = $eventID";
this my te_event table screenshot http://prnt.sc/d8e7i1
this is my te_category screenshot http://prntscr.com/d8e87e
I have tried anything but couldn't get what i want please HELP !

use this query:
$sql = "SELECT * FROM te_events
JOIN te_venue
ON te_venue.venueID = te_events.venueID
JOIN te_category ON te_category.catID = te_events.catID
WHERE te_events.eventID = $eventID";

Related

How can I query something with points in variables?

For my site there is a loginsystem where you need to login with your emailadress, but the problem is that my query gives an error when I start writing my emailadress whenever I use a point.
Here is my query:
$sql = "SELECT LeerlingID FROM tblLeerlingen WHERE email = '$myusername' and Wachtwoord = '$mypassword'";
Simply wrap your strings properly:
SELECT LeerlingID FROM tblLeerlingen WHERE email = 'gregoor.maarten.mg#gmail.com' and Wachtwoord = '0dc22c6a909acf658232f6a38e780d7b';

ConcatRelated() - query or tables

I have similar issue to this question Combine values from related rows into a single concatenated string value.
I've got two queries:
This is what it looks like now without ConcatRelated():
I need to get return:
I tried to use this SQL:
SELECT DISTINCT
Q_Fakt1.FakturaID,
Q_Fakt1.DatumVystavenia,
Q_Fakt1.DatumSplatnosti,
Q_Fakt2.Pismeno,
ConcatRelated(
"pismeno",
"Q_Fakt2",
"FakturaID = '" & [Q_Fakt1]![FakturaID] & "'"
) AS Letters
FROM Q_Fakt1 INNER JOIN Q_Fakt2 ON Q_Fakt1.FakturaID = Q_Fakt2.FakturaID;
Result is 7× popup:
ConcatRelated() Error3464: Data type mismatch in criteria expression.
I did the same with Tables but I have little bit more complicated Relations so...
https://i.stack.imgur.com/TM7Cu.png
SQL:
SELECT DISTINCT
Faktury.FakturaID,
Kategorie.Oznacenie,
Faktury.DatumVystavenia,
FakturujemVam.FakturujemVamID,
FakturyDetaily.FakturujemVam,
[DatumVystavenia]+[splatnostFaktury] AS DatumSplatnosti,
ConcatRelated("Oznacenie","kategorie","FakturaID = '" & [FakturaID] & "'") AS Letters
FROM Kategorie INNER JOIN (Faktury INNER JOIN (FakturujemVam INNER JOIN FakturyDetaily ON FakturujemVam.FakturujemVamID = FakturyDetaily.FakturujemVam) ON Faktury.FakturaID = FakturyDetaily.Faktura) ON Kategorie.KategoriaID = FakturujemVam.Kategoria;
Result is 6× popup:
ConcatRelated() Error3061: Too Few parameters. Excepted 1.
Where did I go wrong? Thank you for Help
That's because you're using string delimiters when you're not using a string.
Remove those delimiters, and it will work fine:
ConcatRelated("Oznacenie","kategorie","FakturaID = " & [FakturaID] ) AS Letters
SOLVED:
STEP 1
Create Query to merge more tables in one
Datasheet View
Design View
STEP 2
Create another Query & Use ConcatRelated()
Design View
SQL:
SELECT
Q_Part_Bill_Num2.NumBill,
Q_Part_Bill_Num2.C_Mark,
ConcatRelated(
"C_Mark",
"Q_Part_Bill_Num2",
"Q_Part_Bill_Num2!NumBill = " & [Q_Part_Bill_Num2]![NumBill]
) AS PartBillNum2
FROM Q_Part_Bill_Num1 INNER JOIN Q_Part_Bill_Num2 ON Q_Part_Bill_Num1.NumBill = Q_Part_Bill_Num2.NumBill;
STEP 3 - Optional
Edit MODULE to delete / change separator ", "
STEP 4
Create One Last Query to Concatenate everything together.
Design View
SQL:
SELECT DISTINCT
Q_Part_Bill_Num1.PartBillNum1,
Q_Part_Bill_Num3.PartBillNum2,
[PartBillNum1] & [PartBillNum2] AS [Full]
FROM
(T_Bills INNER JOIN Q_Part_Bill_Num1 ON T_Bills.Bills_ID = Q_Part_Bill_Num1.Bills_ID)
INNER JOIN (Q_Part_Bill_Num2 INNER JOIN Q_Part_Bill_Num3
ON (Q_Part_Bill_Num2.NumBill = Q_Part_Bill_Num3.NumBill)
AND (Q_Part_Bill_Num2.C_Mark = Q_Part_Bill_Num3.C_Mark))
ON Q_Part_Bill_Num1.NumBill = Q_Part_Bill_Num2.NumBill;
Use DISTINCT to avoid duplicates.
I Hope this will help someone.
Thank you all, for your time :)

Updating a Microsoft Access 2013 table with data from a pass-through query

I am trying, unsuccessfully so far, to update records in a Microsoft Access 2013 table (called tbl_Data) with data from an AS400 table (LIBRARY.TABLE).
As you can see in my Access 2013 pass-through query below, I am trying to join the access table with the AS400 table using the Prefix & Number fields, and from there, update the access table with Name & Address information from the AS400 table.
Here is my latest attempt:
UPDATE
tbl_Data
SET
tbl_Data.FirstName = a.NINMFR,
tbl_Data.MiddleName = a.NINMMD,
tbl_Data.LastName = a.NINAML,
tbl_Data.BuildingNumber = a.NIBLNR,
tbl_Data.StreetName = a.NISTNM,
tbl_Data.AptSuite = a."NIAPT#",
tbl_Data.Address2 = a.NIADR2,
tbl_Data.City = a.NICITY,
tbl_Data.State = a.NISTAT,
tbl_Data.ZipCode = a.NIZIPC
INNER JOIN
LIBRARY.TABLE a
ON
tbl_Data.Prefix = a.NIPRFX,
tbl_Data.Number = a.NIPLNR;
When I run this query, I get an error that says:
OBDC--call failed.
[IBM][System i Access ODBC Driver][DB2 for i5/OS]SQL0199 - Keyword INNER not expected. Valid tokens: USE SKIP WAIT WITH WHERE. (#-199)
I would really appreciate any assistance, as I'm out of ideas.
Thanks!
That is Microsoft specific syntax for an update, it does not work on DB2. Try this:
UPDATE
tbl_Data
SET
(tbl_Data.FirstName,
tbl_Data.MiddleName,
tbl_Data.LastName,
tbl_Data.BuildingNumber,
tbl_Data.StreetName,
tbl_Data.AptSuite,
tbl_Data.Address2,
tbl_Data.City,
tbl_Data.State,
tbl_Data.ZipCode)
=
(SELECT
a.NINMFR,
a.NINMMD,
a.NINAML,
a.NIBLNR,
a.NISTNM,
a."NIAPT#",
a.NIADR2,
a.NICITY,
a.NISTAT,
a.NIZIPC
FROM
library.table a
WHERE
tbl_Data.Prefix = a.NIPRFX,
tbl_Data.Number = a.NIPLNR)
WHERE
EXISTS (
SELECT *
FROM
library.table a
WHERE
tbl_Data.Prefix = a.NIPRFX,
tbl_Data.Number = a.NIPLNR);

I get an error 3075 (Missing operator) when trying to run an sql. update query

The VBA code is:
''sql1 = "select InvoiceCNotes.[docsetamount] ,InvoiceCNotes.[docsetamount] + AllocationsTEMP.[paidamount] from AllocationsTEMP inner join InvoiceCNotes on AllocationsTEMP.Docnumber = InvoiceCNotes.Docnumber where InvoiceCNotes.[docnumber] = AllocationsTEMP.[docnumber] AND AllocationsTEMP.[paidamount] <> 0"
sqlline = sql1
DoCmd.RunSQL sql1
The code as displayed in sqlline above, is as follows:
Update InvoiceCNotes
set InvoiceCNotes.[docsetamount] = InvoiceCNotes.[docsetamount] + AllocationsTEMP.[paidamount]
from AllocationsTEMP inner join InvoiceCNotes
on AllocationsTEMP.Docnumber = InvoiceCNotes.Docnumber
where InvoiceCNotes.[docnumber] = AllocationsTEMP.[docnumber]
AND AllocationsTEMP.[paidamount] <> 0
I have looked at other questions here regarding the same error, but still I am missing something.
From previous questions, I added the table names, and bracketed the field names.
I checked the table specs to see that docsetamount and paidamount are both defined as [NUMBER,double,fixed,2], the two docnumbers are both long integers, and paidamount is also NUMBER,double,fixed,2
Now I am possibly staring into the problem and not noticing my error, as I have developed quite a few apps in Access over the past five years (since retirement I should add) so I must have done something wrong.
Do you notice the mistake?
The UPDATE t1 SET t1.f=foo FROM t1 JOIN t2 syntax with the FROM is from Sql Server.
In Access SQL you put the JOIN in the first clause, like this:
UPDATE InvoiceCNotes INNER JOIN AllocationsTEMP
ON InvoiceCNotes.Docnumber = AllocationsTEMP.Docnumber
SET InvoiceCNotes.[docsetamount] = InvoiceCNotes.[docsetamount] + AllocationsTEMP.[paidamount]
WHERE AllocationsTEMP.[paidamount] <> 0
where InvoiceCNotes.[docnumber] = AllocationsTEMP.[docnumber] is superfluous because it's already in the JOIN condition.
I found a totally different syntax - and it works just fine.
Maybe my original source was wrong, as I did exactly hat it said.
My new syntax for the update is:
UPDATE InvoiceCNotes INNER JOIN AllocationsTEMP
ON InvoiceCNotes.Docnumber = AllocationsTEMP.Docnumber
SET InvoiceCNotes.docsetamount = InvoiceCNotes.[docsetamount]+AllocationsTEMP.[paidamount]
WHERE (((InvoiceCNotes.docnumber)=[AllocationsTEMP].[docnumber])
AND ((AllocationsTEMP.paidamount)<>False))
Maybe this question should just be removed - it will cause confusion rather than to be helpful. I can't do that, or I would.
Apologies to whoever might have tried to help - and thanks for the effort.
This is now SOLVED

Codeigniter Sql Error

function get_result_professions($key_word)
{
$sql = "SELECT users.name FROM users
inner join users_has_professions on users_has_professions.users_id = users.id
inner join professions on users_has_professions.professions_id = professions.id
where professions.key_word = ? ";
return $this->db->get()->query($sql, $key_word);
}
When I execute this code I receive the following error:
A Database Error Occurred
Error Number: 1096
No tables used
SELECT *
Filename: /var/www/expertt/models/search_model.php
Line Number: 31
How can I solve this problem? Thanks in advance.
$this->db->get() must contain an table name. in your case you want to remove it sindse you have an custom query so your function wil look like this:
function get_result_professions($key_word)
{
$sql = "SELECT users.name FROM users
inner join users_has_professions on users_has_professions.users_id = users.id
inner join professions on users_has_professions.professions_id = professions.id
where professions.key_word = '$key_word' ";
return $this->db->query($sql);
}
The $this->db->get() method in CodeIgniter's Active record requires a table name parameter (see the Active Record Documentation for more info) when used to query a table, unless you have previously build up the query using one of the other provided methods.
Usually when building up joins like you are doing you would use the select/ join methods provided by Active Record, like so
$this->db->select('users.name')->from('users')
->join('users_has_professions', 'users_has_professions.users_id = users.id')
->join('professions', 'users_has_professions.professions_id = professions.id')
->where('professions.key_word', $key_word);
(untested as I don't have your database to run it against)
You can then use the $this->db->get() method to retrieve the results like so
$results = $this->db->get();
foreach($query->result() as $row) {
//code here
}