How could I filter duplicates? [closed] - php

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
INFORMATION:
TABLE = giveaway
FORM 1 = id
FORM 2 = username
FORM 3 = userid
FORM 4 = wish
END OF INFORMATION
I am trying to make it filter through duplicate usernames and userids
NOTE: people enter the userid and the username (it is for a giveaway)
can anyone post me some code to do that?

Try this one:
SELECT `username`,`userid` FROM `giveaway` group by `username` HAVING COUNT(`username`) > 1 UNION SELECT `username`,`userid` FROM `giveaway` group by `userid` HAVING COUNT(`userid`) > 1

drop table test;
/
create table test
(
id number,
username varchar2(20),
userid number,
wish varchar2(40)
);
/
insert into test
values(1,'A',1,'ZXX');
/
insert into test
values(1,'A',1,'YYY');
/
insert into test
values(1,'B',2,'ZXX');
/
SELECT * FROM
(
SELECT ID ,USERNAME,USERID,COUNT(*) OVER (PARTITION BY USERNAME,USERID) AS CNT
FROM TEST
)
WHERE CNT <2
This will give you unique values

Related

php code to delete value table 2 from value of table 1 [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
I am php beginner.
I would like to read email contain in table 1 and with the value selected deleted the corresponding email of the table 2 ?
May you provide me some info to manage it ?
select email_table1 from table1.
delete from table2 where email = email_table1.
Thanks
Greg
There's little information to form an answer but you could use a sub select.
Something like this presuming you're using MySQL or similar.
DELETE FROM `table1` WHERE id = (
SELECT `referenceID` FROM `table2` WHERE `email` = 'the#email.com' LIMIT 1
) LIMIT 1;

How to drop a table with register form (SQL Injection) (closed) [duplicate]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I am trying to fetch bulk data from a website database but could not succeed. Can somebody suggest if SQL injection is possible and how to do in this case.
There are many ways to do SQL Injection to a website similar to the one you provided.
In the where clause it is expecting ac_no. I assume that this value is being passed from the browser as user input. In that case you can pass ac_no value along with or 1 = 1. e.g where ac_no = 123 or 1 = 1. It returns everything from the table RollPdf1.
For string comparison you can add "" = "" to the where clause.
If you want to perform other select operations ( if you know other table names) then you can append select statements delmited by ;.
UNION operator :
If you know the data types of the columns selected in the query then you can use UNION to get additional data from other tables.
e.g
original query : select name, age, sex from table1 where id = 1
sql injected query : select name, age, sex from table1 where id = 1 AND 1 = 2 UNION select username, id, password from userstable or someother table.

Select all data from a second table where name is equal to a column value from first table [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago.
Improve this question
I am working with a MySQL database wherein I have tables named as follows:
Users
1247483647
2147483613
2047483641
The columns in Users are as follows:
userEmail
compId
How can I structure an SQL query which will:
a) Select the compId from the Users table where userEmail is equal to an email address provided via a mysqli prepared statement.
b) Then find the table with a table name which matches the compId and select all data from it?
I have so far tried as follows (to no avail):
$sql = "
SELECT * FROM table_name
WHERE table_name =
(SELECT compId
FROM Users
WHERE userEmail = ?)
";
Thanks in advance.
You have to build the SQL string from the INFORMATION_SCHEMA.TABLES
select #querystring := CONCAT('SELECT * FROM ', table_name)
from information_schema.TABLES
where TABLE_NAME =
(SELECT
compId
FROM
Users
WHERE
userEmail = {?})
PREPARE statement from #querystring;
EXECUTE statement
I'm not the handiest with PHP but this works for me as long as you inject the userEmail in the {?} where I designated as a parameter.

Return the latest 10 records from a mysql query [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
Here's the link what I mean -
i.stack.imgur.com/yYQbu.png.
Query from 2 columns name and version.(may only with one column I'll put version in name column).
So , Wheres matches name from title or post from same column name and returns all lowest number from version(column).
Can anyone give me example of some query?
So far I have this query:
$name = substr($row[2],0,10);
$q = mysql_query("SELECT name from films WHERE name LIKE '$name'") or die(mysql_error());
I'm assuming your table has an id column as the primary key with auto increment.
In which case, you need to add an ORDER BY and LIMIT to your query.
$q = mysql_query("SELECT name from films WHERE name LIKE '$name' ORDER BY id DESC LIMIT 10") or die(mysql_error());
ORDER BY id DESC will make your query put the latest records first.
LIMIT 10 will ensure that you only grab 10 records.

updating id to max(id)+1 [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
can someone please help me with the below mysql query:
I want to build a query like:
UPDATE users
SET ref_id = (select max(ref_id)where `role_id`=5) +1
WHERE user_id =102
AND `role_id`=5
where your FROM clause in subquery???
UPDATE users
SET ref_id =
(select max(ref_id) FROM ???? where role_id=5) + 1
WHERE user_id =102 and role_id=5
Ok I tried a similar request and I had this MySQL error :
1093 - You can't specify target table 'my_table' for update in FROM clause
Try using the following request :
UPDATE `users`
SET
`ref_id` =
(
( SELECT max_id FROM ( SELECT MAX(ref_id) AS max_id FROM users WHERE `role_id`= 5) AS sub_selected_value )
+ 1
)
WHERE `user_id` = 102 AND `role_id` =5
Please keep in mind that may not be the most efficient solution if performance matters because it uses temporary tables.

Categories